cpython: 775319cebaa3 (original) (raw)
Mercurial > cpython
changeset 74036:775319cebaa3 2.7
Issue #11870: threading: Properly reinitialize threads internal locks and condition variables to avoid deadlocks in child processes. [#11870]
Charles-François Natali neologix@free.fr | |
---|---|
date | Sun, 18 Dec 2011 18:22:24 +0100 |
parents | 038616802b65 |
children | d9bb270feb58 64d670a8b183 |
files | Lib/threading.py Misc/NEWS |
diffstat | 2 files changed, 8 insertions(+), 8 deletions(-)[+] [-] Lib/threading.py 13 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/threading.py +++ b/Lib/threading.py @@ -878,22 +878,19 @@ def _after_fork(): current = current_thread() with _active_limbo_lock: for thread in _active.itervalues():
# Any lock/condition variable may be currently locked or in an[](#l1.7)
# invalid state, so we reinitialize them.[](#l1.8)
if hasattr(thread, '_reset_internal_locks'):[](#l1.9)
thread._reset_internal_locks()[](#l1.10) if thread is current:[](#l1.11) # There is only one active thread. We reset the ident to[](#l1.12) # its new value since it can have changed.[](#l1.13) ident = _get_ident()[](#l1.14) thread._Thread__ident = ident[](#l1.15)
# Any condition variables hanging off of the active thread may[](#l1.16)
# be in an invalid state, so we reinitialize them.[](#l1.17)
if hasattr(thread, '_reset_internal_locks'):[](#l1.18)
thread._reset_internal_locks()[](#l1.19) new_active[ident] = thread[](#l1.20) else:[](#l1.21) # All the others are already stopped.[](#l1.22)
# We don't call _Thread__stop() because it tries to acquire[](#l1.23)
# thread._Thread__block which could also have been held while[](#l1.24)
# we forked.[](#l1.25)
thread._Thread__stopped = True[](#l1.26)
thread._Thread__stop()[](#l1.27)
_limbo.clear() _active.clear()
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -86,6 +86,9 @@ Core and Builtins Library ------- +- Issue #11870: threading: Properly reinitialize threads internal locks and