mirror of
https://github.com/python/cpython.git
synced 2025-08-19 00:00:48 +00:00
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.
This commit is contained in:
parent
04cb72f968
commit
7dfc874a48
2 changed files with 11 additions and 2 deletions
|
@ -295,6 +295,8 @@ class Pool(object):
|
||||||
while pool._worker_handler._state == RUN and pool._state == RUN:
|
while pool._worker_handler._state == RUN and pool._state == RUN:
|
||||||
pool._maintain_pool()
|
pool._maintain_pool()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
# send sentinel to stop workers
|
||||||
|
pool._taskqueue.put(None)
|
||||||
debug('worker handler exiting')
|
debug('worker handler exiting')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -413,7 +415,6 @@ class Pool(object):
|
||||||
if self._state == RUN:
|
if self._state == RUN:
|
||||||
self._state = CLOSE
|
self._state = CLOSE
|
||||||
self._worker_handler._state = CLOSE
|
self._worker_handler._state = CLOSE
|
||||||
self._taskqueue.put(None)
|
|
||||||
|
|
||||||
def terminate(self):
|
def terminate(self):
|
||||||
debug('terminating pool')
|
debug('terminating pool')
|
||||||
|
@ -447,7 +448,6 @@ class Pool(object):
|
||||||
|
|
||||||
worker_handler._state = TERMINATE
|
worker_handler._state = TERMINATE
|
||||||
task_handler._state = TERMINATE
|
task_handler._state = TERMINATE
|
||||||
taskqueue.put(None) # sentinel
|
|
||||||
|
|
||||||
debug('helping task handler/workers to finish')
|
debug('helping task handler/workers to finish')
|
||||||
cls._help_stuff_finish(inqueue, task_handler, len(pool))
|
cls._help_stuff_finish(inqueue, task_handler, len(pool))
|
||||||
|
@ -457,6 +457,11 @@ class Pool(object):
|
||||||
result_handler._state = TERMINATE
|
result_handler._state = TERMINATE
|
||||||
outqueue.put(None) # sentinel
|
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.
|
# Terminate workers which haven't already finished.
|
||||||
if pool and hasattr(pool[0], 'terminate'):
|
if pool and hasattr(pool[0], 'terminate'):
|
||||||
debug('terminating workers')
|
debug('terminating workers')
|
||||||
|
|
|
@ -51,6 +51,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- 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 #7311: fix HTMLParser to accept non-ASCII attribute values.
|
- Issue #7311: fix HTMLParser to accept non-ASCII attribute values.
|
||||||
|
|
||||||
- Issue #10963: Ensure that subprocess.communicate() never raises EPIPE.
|
- Issue #10963: Ensure that subprocess.communicate() never raises EPIPE.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue