def mytask(num):
    print('Started task, sleeping %s' % num)
time.sleep(num)
return num
pool = multiprocess.Pool(process_count)
jobs = []
items = [1, 2, 3, 4, 5, 3, 2, 3, 4, 5, 2, 3, 2, 3, 4, 5, 6, 4]
job_count = 0
for job in pool.imap_unordered(mytask, items):
    jobs.append(job)
job_count += 1
incomplete = len(items) - job_count
unsubmitted = max(0, incomplete - process_count)
print('Jobs incomplete: %s. Unsubmitted: %s' % incomplete, unsubmitted)
pool.close()
Python: How can I check the number of pending tasks in a multiprocessing.Pool?