Issue #11870: threading: Properly reinitialize threads internal locks and

condition variables to avoid deadlocks in child processes.
parent f3d35f0e
...@@ -878,22 +878,19 @@ def _after_fork(): ...@@ -878,22 +878,19 @@ def _after_fork():
current = current_thread() current = current_thread()
with _active_limbo_lock: with _active_limbo_lock:
for thread in _active.itervalues(): for thread in _active.itervalues():
# Any lock/condition variable may be currently locked or in an
# invalid state, so we reinitialize them.
if hasattr(thread, '_reset_internal_locks'):
thread._reset_internal_locks()
if thread is current: if thread is current:
# There is only one active thread. We reset the ident to # There is only one active thread. We reset the ident to
# its new value since it can have changed. # its new value since it can have changed.
ident = _get_ident() ident = _get_ident()
thread._Thread__ident = ident thread._Thread__ident = ident
# Any condition variables hanging off of the active thread may
# be in an invalid state, so we reinitialize them.
if hasattr(thread, '_reset_internal_locks'):
thread._reset_internal_locks()
new_active[ident] = thread new_active[ident] = thread
else: else:
# All the others are already stopped. # All the others are already stopped.
# We don't call _Thread__stop() because it tries to acquire thread._Thread__stop()
# thread._Thread__block which could also have been held while
# we forked.
thread._Thread__stopped = True
_limbo.clear() _limbo.clear()
_active.clear() _active.clear()
......
...@@ -86,6 +86,9 @@ Core and Builtins ...@@ -86,6 +86,9 @@ Core and Builtins
Library Library
------- -------
- Issue #11870: threading: Properly reinitialize threads internal locks and
condition variables to avoid deadlocks in child processes.
- Issue #8035: urllib: Fix a bug where the client could remain stuck after a - Issue #8035: urllib: Fix a bug where the client could remain stuck after a
redirection or an error. redirection or an error.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment