Created
March 6, 2014 21:08
-
-
Save tristanwietsma/9399663 to your computer and use it in GitHub Desktop.
Futures in Python 3.3
This file contains 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
# 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