Skip to content

Instantly share code, notes, and snippets.

@meonkeys
Created April 5, 2011 02:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save meonkeys/902947 to your computer and use it in GitHub Desktop.
import multiprocessing
import time
def mytask(num):
print('Started task, sleeping %s' % num)
time.sleep(num)
pool = multiprocessing.Pool(4)
jobs = pool.map_async(mytask, [1,2,3,4,5,3,2,3,4,5,2,3,2,3,4,5,6,4], chunksize=1)
pool.close()
while True:
if not jobs.ready():
print('We\'re not done yet, %s tasks to go!' % jobs._number_left)
time.sleep(1)
else:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment