Last active
July 29, 2021 15:41
-
-
Save luizhenriquefbb/3e6da48038c8bcc9fc549a3f363efc1a to your computer and use it in GitHub Desktop.
example of a for in a pool of threads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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