diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-04-10 22:22:08 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-04-10 22:22:08 (GMT) |
commit | 753009a657e1f53878a351d5cd4be1cbbf483cf7 (patch) | |
tree | 25dae24bec1ed6c3a88eaaa0d56d59b1dfe3692a | |
parent | eb9e074dcaeaf4212750f32c106fb12fc4d9f57c (diff) | |
parent | bed9a5b6b38e30b4a207237ac9753cbfa0f2ae99 (diff) | |
download | cpython-753009a657e1f53878a351d5cd4be1cbbf483cf7.zip cpython-753009a657e1f53878a351d5cd4be1cbbf483cf7.tar.gz cpython-753009a657e1f53878a351d5cd4be1cbbf483cf7.tar.bz2 |
Merge from 3.2 (issue #11814, issue #8428)
-rw-r--r-- | Lib/multiprocessing/pool.py | 11 | ||||
-rw-r--r-- | Misc/NEWS | 6 |
2 files changed, 14 insertions, 3 deletions
diff --git a/Lib/multiprocessing/pool.py b/Lib/multiprocessing/pool.py index ff7c29c..92170f2 100644 --- a/Lib/multiprocessing/pool.py +++ b/Lib/multiprocessing/pool.py @@ -322,6 +322,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 + pool._taskqueue.put(None) debug('worker handler exiting') @staticmethod @@ -440,7 +442,6 @@ class Pool(object): if self._state == RUN: self._state = CLOSE self._worker_handler._state = CLOSE - self._taskqueue.put(None) def terminate(self): debug('terminating pool') @@ -474,7 +475,6 @@ class Pool(object): worker_handler._state = TERMINATE task_handler._state = TERMINATE - taskqueue.put(None) # sentinel debug('helping task handler/workers to finish') cls._help_stuff_finish(inqueue, task_handler, len(pool)) @@ -484,6 +484,11 @@ class Pool(object): result_handler._state = TERMINATE outqueue.put(None) # sentinel + # We must wait for the worker handler to exit before terminating + # workers because we don't want workers to be restarted behind our back. + debug('joining worker handler') + worker_handler.join() + # Terminate workers which haven't already finished. if pool and hasattr(pool[0], 'terminate'): debug('terminating workers') @@ -495,7 +500,7 @@ class Pool(object): task_handler.join() debug('joining result handler') - task_handler.join() + result_handler.join() if pool and hasattr(pool[0], 'terminate'): debug('joining pool workers') @@ -98,6 +98,12 @@ Core and Builtins Library ------- +- Issue #11814: Fix likely typo in multiprocessing.Pool._terminate(). + +- 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. + - Issue #2650: re.escape() no longer escapes the '_'. - Issue #11757: select.select() now raises ValueError when a negative timeout |