summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2011-10-24 16:43:51 (GMT)
committerCharles-François Natali <neologix@free.fr>2011-10-24 16:43:51 (GMT)
commit46f990e58cb462bbf98fef88a3ba41ffa4a4e35d (patch)
tree5493080bcfbf94367a3186de82cbfa3f2f4e8ff6 /Lib/multiprocessing
parent22dabb6ffa5860ee08138c2f67b0406d566df5f4 (diff)
downloadcpython-46f990e58cb462bbf98fef88a3ba41ffa4a4e35d.zip
cpython-46f990e58cb462bbf98fef88a3ba41ffa4a4e35d.tar.gz
cpython-46f990e58cb462bbf98fef88a3ba41ffa4a4e35d.tar.bz2
Issue #10332: multiprocessing: fix a race condition when a Pool is closed
before all tasks have completed.
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r--Lib/multiprocessing/pool.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py
index c66876a..bcbf7e3 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -294,7 +294,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