I am confused as to what _number_left
is supposed to return. I assumed it was the number tasks remaining in the pool, but it does not appear to provide the correct value in my code. For example, if I have a pool of 10 workers counting to the number 1000, I would expect result._number_left
to countdown from 1000. However, it only tells me I have 40 left until the code is about finished. Am I missing something here?
Code:
import multiprocessing
import time
def do_something(x):
print x
time.sleep(1)
return
def main():
pool = multiprocessing.Pool(10)
result = pool.map_async(do_something, [x for x in range(1000)])
while not result.ready():
print("num left: {}".format(result._number_left))
result.wait(timeout=1)
if __name__ == "__main__":
main()