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

Lib/threading.py
Misc/NEWS

index 6a06feb63526844e49fc0f01c8a981117ef70901..e48bf5ca67ae56e2d5ea7373f27116deaa9a5425 100644 (file)
@@ -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()
index 455399cdc2842203a54121e0962120081bf2bc0f..5118afdd67e24516a1ac7d9249e8111bebd3fd99 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -86,6 +86,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.