cpython: dfc61dc14f59 (original) (raw)
Mercurial > cpython
changeset 69239:dfc61dc14f59 2.7
Issue #8428: Fix a race condition in multiprocessing.Pool when terminating worker processes: new processes would be spawned while the pool is being shut down. Patch by Charles-François Natali. [#8428]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Mon, 11 Apr 2011 00:26:42 +0200 |
parents | 3630bc3d5a88 |
children | 28705a7987c5 |
files | Lib/multiprocessing/pool.py Misc/NEWS |
diffstat | 2 files changed, 11 insertions(+), 2 deletions(-)[+] [-] Lib/multiprocessing/pool.py 9 Misc/NEWS 4 |
line wrap: on
line diff
--- a/Lib/multiprocessing/pool.py +++ b/Lib/multiprocessing/pool.py @@ -295,6 +295,8 @@ class Pool(object): while pool._worker_handler._state == RUN and pool._state == RUN: pool._maintain_pool() time.sleep(0.1)
# send sentinel to stop workers[](#l1.7)
pool._taskqueue.put(None)[](#l1.8) debug('worker handler exiting')[](#l1.9)
@staticmethod @@ -413,7 +415,6 @@ class Pool(object): if self._state == RUN: self._state = CLOSE self._worker_handler._state = CLOSE
self._taskqueue.put(None)[](#l1.16)
def terminate(self): debug('terminating pool') @@ -447,7 +448,6 @@ class Pool(object): worker_handler._state = TERMINATE task_handler._state = TERMINATE
taskqueue.put(None) # sentinel[](#l1.24)
debug('helping task handler/workers to finish') cls._help_stuff_finish(inqueue, task_handler, len(pool)) @@ -457,6 +457,11 @@ class Pool(object): result_handler._state = TERMINATE outqueue.put(None) # sentinel
# We must wait for the worker handler to exit before terminating[](#l1.32)
# workers because we don't want workers to be restarted behind our back.[](#l1.33)
debug('joining worker handler')[](#l1.34)
worker_handler.join()[](#l1.35)
+ # Terminate workers which haven't already finished. if pool and hasattr(pool[0], 'terminate'): debug('terminating workers')
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -51,6 +51,10 @@ Core and Builtins Library ------- +- Issue #8428: Fix a race condition in multiprocessing.Pool when terminating