Skip to content

Instantly share code, notes, and snippets.

@tristanwietsma
Created March 6, 2014 21:08
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 tristanwietsma/9399663 to your computer and use it in GitHub Desktop.
Save tristanwietsma/9399663 to your computer and use it in GitHub Desktop.
Futures in Python 3.3
# python 3.3: example of futures
import time
import concurrent.futures
def add(x, y):
time.sleep(2)
return x + y
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as queue:
jobs = [queue.submit(add, 1, i) for i in range(10)]
for job in jobs:
print(job.result())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment