Hello!
When i write sequential code to upload videos to genai, like this (omit what is here async
):
for video in videos:
uploaded_videos.append(self._upload_video(video))
_upload_video:
video_file = None
while True:
try:
logger.info(f"Uploading video {video.name}")
video_file = await self.client.aio.files.upload(file=Path(video.path))
except httpx.TimeoutException:
logger.warning(f"Timeout while uploading video {video.name}. Retrying...")
await asyncio.sleep(10)
continue
break
Everything works great - but it is very slow.
I want to upload video files (I split 30 min video into 2min chunks) asynchronous, in parallel.
When I do this:
tasks = [self._upload_video(video) for video in videos]
return await asyncio.gather(*tasks)
I got all the time DEBUG:httpcore.http11:send_request_body.failed exception=WriteTimeout(TimeoutError())
. How to deal with it?
Is it possible to upload files in parallel, how can I fix this problem with WriteTimeout
?
I tried to submit the images in groups of three and managed to reduce the loading time twice.
Are there any other options? (I also used semaphores, but did not see any speedup.)