Skip to content

Instantly share code, notes, and snippets.

@luizhenriquefbb
Last active July 29, 2021 15:41
Show Gist options
  • Save luizhenriquefbb/3e6da48038c8bcc9fc549a3f363efc1a to your computer and use it in GitHub Desktop.
Save luizhenriquefbb/3e6da48038c8bcc9fc549a3f363efc1a to your computer and use it in GitHub Desktop.
example of a for in a pool of threads
def lambda_handler(event, context):
from concurrent.futures import ThreadPoolExecutor, as_completed
def task(data):
print(f"computing data {data}")
with ThreadPoolExecutor(max_workers = 5) as executor:
future_to_data = { executor.submit(task, data) : data for data in list(range(100)) }
response = []
for future in as_completed(future_to_data):
computed_data = future_to_data[future]
response.append(computed_data)
print("end of pool??")
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment