Demo multiprocessing Python module and "tasks left" code. See http://stackoverflow.com/questions/5542868/python-how-can-i-check-the-number-of-pending-tasks-in-a-multiprocessing-pool
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
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