Skip to content

Commit

Permalink
limit the number of concurrent downloads if images from s3
Browse files Browse the repository at this point in the history
  • Loading branch information
nrjadkry committed Jan 20, 2025
1 parent d09300d commit 21ce94d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/backend/app/projects/image_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(
self.db = db
self.task_id = task_id
self.task_ids = task_ids or ([] if task_id is None else [task_id])
self.max_concurrent_downloads = 4

def options_list_to_dict(
self, options: List[Dict[str, Any]] = None
Expand Down Expand Up @@ -109,7 +110,8 @@ def download_images_from_s3(
)
objects = list_objects_from_bucket(bucket_name, prefix)

with ThreadPoolExecutor() as executor:
# Limit the number of images to download concurrently
with ThreadPoolExecutor(max_workers=self.max_concurrent_downloads) as executor:
executor.map(
lambda obj: self.download_object(bucket_name, obj, local_dir),
objects,
Expand Down

0 comments on commit 21ce94d

Please sign in to comment.