summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2011-12-18 17:22:24 (GMT)
committerCharles-François Natali <neologix@free.fr>2011-12-18 17:22:24 (GMT)
commit41616300b1a29b2bf65071a7e117f34367126bcb (patch)
tree7099e9f9b0e600edc99b423dd8a858c3a8bb9fa6 /Lib
parentf3d35f0efe4bd669782e29a9ccf21570878ed319 (diff)
downloadcpython-41616300b1a29b2bf65071a7e117f34367126bcb.zip
cpython-41616300b1a29b2bf65071a7e117f34367126bcb.tar.gz
cpython-41616300b1a29b2bf65071a7e117f34367126bcb.tar.bz2
Issue #11870: threading: Properly reinitialize threads internal locks and
condition variables to avoid deadlocks in child processes.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/threading.py13
1 files changed, 5 insertions, 8 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 6a06feb..e48bf5c 100644
--- 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
+ # invalid state, so we reinitialize them.
+ if hasattr(thread, '_reset_internal_locks'):
+ thread._reset_internal_locks()
if thread is current:
# There is only one active thread. We reset the ident to
# its new value since it can have changed.
ident = _get_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
else:
# All the others are already stopped.
- # We don't call _Thread__stop() because it tries to acquire
- # thread._Thread__block which could also have been held while
- # we forked.
- thread._Thread__stopped = True
+ thread._Thread__stop()
_limbo.clear()
_active.clear()