Created
December 4, 2012 20:40
-
-
Save graingert/4208460 to your computer and use it in GitHub Desktop.
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
from multiprocessing import Pool, cpu_count | |
import time | |
from random import randint | |
def roll(dice=1, sides=6): | |
try: | |
return [randint(1, sides) for i in range(dice)] | |
except: | |
return [] | |
def f(x): | |
time.sleep(roll(1, 6)[0]) | |
return x | |
if __name__ == '__main__': | |
p = Pool(cpu_count()) | |
for item in p.imap(f, range(100)): | |
print item |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment