Skip to content

Instantly share code, notes, and snippets.

@orcaman
Created February 18, 2021 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orcaman/0f4a389b0dcbdc0df6c129bfe150008c to your computer and use it in GitHub Desktop.
Save orcaman/0f4a389b0dcbdc0df6c129bfe150008c to your computer and use it in GitHub Desktop.
with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_PROC) as executor:
for entity_to_load in entities_to_load:
data_list = entities_to_load[entity_to_load]
batches = chunks(data_list, 25)
for batch in batches:
futures.append(executor.submit(dal.dynamo.load_batch, entity_to_load, batch))
for future in concurrent.futures.as_completed(futures):
results.append(future.result())
def chunks(lst, n):
"""Yield successive n-sized chunks from lst."""
for i in range(0, len(lst), n):
yield lst[i:i + n]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment