summaryrefslogtreecommitdiffstats
path: root/Lib/multiprocessing/pool.py
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2011-10-24 16:45:29 (GMT)
committerCharles-François Natali <neologix@free.fr>2011-10-24 16:45:29 (GMT)
commitf8859e1808eff603b727d1adbeb38f745c9fedb5 (patch)
tree4491834ef0c5d5be6283d61894940e321d33b18f /Lib/multiprocessing/pool.py
parentd6ca6c2b32118fec10d28b1a23d97f8e6b536d04 (diff)
downloadcpython-f8859e1808eff603b727d1adbeb38f745c9fedb5.zip
cpython-f8859e1808eff603b727d1adbeb38f745c9fedb5.tar.gz
cpython-f8859e1808eff603b727d1adbeb38f745c9fedb5.tar.bz2
Issue #10332: multiprocessing: fix a race condition when a Pool is closed
before all tasks have completed.
Diffstat (limited to 'Lib/multiprocessing/pool.py')
-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 e450319..04e7c44 100644
--- a/Lib/multiprocessing/pool.py
+++ b/Lib/multiprocessing/pool.py
@@ -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