Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- from multiprocessing import Pool
- import random, time
- def worker(key):
- # Some process which occassionally takes a long time
- coin = random.choice(range(20))
- if coin == 0:
- print('long_runner')
- time.sleep(random.choice(range(1000)))
- if coin >= 1:
- print('short timmer')
- time.sleep(1)
- if __name__ == '__main__':
- keys = range(30000)
- p = Pool(20)
- p.map(worker,keys)
Advertisement
Add Comment
Please, Sign In to add comment