From 3b13580e0a6838bf83efaba0fb2cc12a3b653820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Fran=C3=A7ois=20Natali?= Date: Sun, 18 Dec 2011 18:45:16 +0100 Subject: Issue #11870: threading: Properly reinitialize threads internal locks and condition variables to avoid deadlocks in child processes. --- Lib/threading.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'Lib/threading.py') diff --git a/Lib/threading.py b/Lib/threading.py index 8d505b7d65..2362be69b5 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -1047,21 +1047,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() -- cgit v1.2.1