]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #11870: threading: Properly reinitialize threads internal locks and
authorCharles-François Natali <neologix@free.fr>
Sun, 18 Dec 2011 17:35:09 +0000 (18:35 +0100)
committerCharles-François Natali <neologix@free.fr>
Sun, 18 Dec 2011 17:35:09 +0000 (18:35 +0100)
condition variables to avoid deadlocks in child processes.

Lib/threading.py
Misc/NEWS

index 6653f6ef651fac06ed32bba8d0ccc0f9cfa75897..043e6c82afbac0d63db75f4362bd48dde6b0cc9f 100644 (file)
@@ -1068,21 +1068,18 @@ def _after_fork():
     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()
index 72b33b99f3bd638a462fd9fa4c6f6d54ab6de3d6..4be3a6b6f8f077fa4a72215b9db54fd0339afc4c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -97,6 +97,9 @@ Core and Builtins
 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
   redirection or an error.