Guest User

Untitled

a guest
Jan 1st, 2016
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from multiprocessing import Pool
  4. import random, time
  5.  
  6. def worker(key):
  7. # Some process which occassionally takes a long time
  8. coin = random.choice(range(20))
  9. if coin == 0:
  10. print('long_runner')
  11. time.sleep(random.choice(range(1000)))
  12. if coin >= 1:
  13. print('short timmer')
  14. time.sleep(1)
  15.  
  16. if __name__ == '__main__':
  17. keys = range(30000)
  18. p = Pool(20)
  19. p.map(worker,keys)
Advertisement
Add Comment
Please, Sign In to add comment