Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d5f9e7

Browse files
author
Charles-François Natali
committed
Issue #11870: threading: Properly reinitialize threads internal locks and
condition variables to avoid deadlocks in child processes.
1 parent cf53ae2 commit 6d5f9e7

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

Lib/threading.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,21 +1068,18 @@ def _after_fork():
10681068
current = current_thread()
10691069
with _active_limbo_lock:
10701070
for thread in _active.values():
1071+
# Any lock/condition variable may be currently locked or in an
1072+
# invalid state, so we reinitialize them.
1073+
thread._reset_internal_locks()
10711074
if thread is current:
10721075
# There is only one active thread. We reset the ident to
10731076
# its new value since it can have changed.
10741077
ident = _get_ident()
10751078
thread._ident = ident
1076-
# Any condition variables hanging off of the active thread may
1077-
# be in an invalid state, so we reinitialize them.
1078-
thread._reset_internal_locks()
10791079
new_active[ident] = thread
10801080
else:
10811081
# All the others are already stopped.
1082-
# We don't call _Thread__stop() because it tries to acquire
1083-
# thread._Thread__block which could also have been held while
1084-
# we forked.
1085-
thread._stopped = True
1082+
thread._stop()
10861083

10871084
_limbo.clear()
10881085
_active.clear()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ Core and Builtins
9797
Library
9898
-------
9999

100+
- Issue #11870: threading: Properly reinitialize threads internal locks and
101+
condition variables to avoid deadlocks in child processes.
102+
100103
- Issue #8035: urllib: Fix a bug where the client could remain stuck after a
101104
redirection or an error.
102105

0 commit comments

Comments
 (0)