diff Lib/threading.py @ 74037:de962ec0faaa 3.2

Issue #11870: threading: Properly reinitialize threads internal locks and condition variables to avoid deadlocks in child processes.
author Charles-François Natali <neologix@free.fr>
date Sun, 18 Dec 2011 18:35:09 +0100
parents e19ccbbe70dd
children eb39d862a250 336805423372
line wrap: on
line diff
--- a/Lib/threading.py	Sun Dec 18 16:05:07 2011 +0100
+++ b/Lib/threading.py	Sun Dec 18 18:35:09 2011 +0100
@@ -1068,21 +1068,18 @@
     current = current_thread()
     with _active_limbo_lock:
         for thread in _active.values():
+            # Any lock/condition variable may be currently locked or in an
+            # invalid state, so we reinitialize them.
+            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._ident = ident
-                # Any condition variables hanging off of the active thread may
-                # be in an invalid state, so we reinitialize them.
-                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._stopped = True
+                thread._stop()
 
         _limbo.clear()
         _active.clear()