Issue #10332: multiprocessing: fix a race condition when a Pool is closed

before all tasks have completed.
This commit is contained in:
Charles-François Natali 2011-10-24 18:45:29 +02:00
parent d6ca6c2b32
commit f8859e1808
3 changed files with 22 additions and 1 deletions

View file

@ -321,7 +321,11 @@ class Pool(object):
@staticmethod
def _handle_workers(pool):
while pool._worker_handler._state == RUN and pool._state == RUN:
thread = threading.current_thread()
# Keep maintaining workers until the cache gets drained, unless the pool
# is terminated.
while thread._state == RUN or (pool._cache and thread._state != TERMINATE):
pool._maintain_pool()
time.sleep(0.1)
# send sentinel to stop workers