Skip to content

Instantly share code, notes, and snippets.

@palawer
Created May 3, 2020 05:15
Show Gist options
  • Save palawer/a6399575da65cfeea2a823210b0737a8 to your computer and use it in GitHub Desktop.
Save palawer/a6399575da65cfeea2a823210b0737a8 to your computer and use it in GitHub Desktop.
from concurrent.futures import ThreadPoolExecutor, as_completed
def get_something(x):
return x
MAX_WORKERS = 8
iterable = range(20)
with ThreadPoolExecutor(max_workers=MAX_WORKERS) as pool:
futures = [pool.submit(get_something, x) for x in iterable]
for future in as_completed(futures):
result = future.result()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment