Skip to content

Commit 243fd01

Browse files
authored
bpo-44422: Fix threading.enumerate() reentrant call (GH-26727)
The threading.enumerate() function now uses a reentrant lock to prevent a hang on reentrant call.
1 parent 1cd3d85 commit 243fd01

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Lib/threading.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,11 @@ class BrokenBarrierError(RuntimeError):
775775
def _newname(name_template):
776776
return name_template % _counter()
777777

778-
# Active thread administration
779-
_active_limbo_lock = _allocate_lock()
778+
# Active thread administration.
779+
#
780+
# bpo-44422: Use a reentrant lock to allow reentrant calls to functions like
781+
# threading.enumerate().
782+
_active_limbo_lock = RLock()
780783
_active = {} # maps thread id to Thread object
781784
_limbo = {}
782785
_dangling = WeakSet()
@@ -1564,7 +1567,7 @@ def _after_fork():
15641567
# by another (non-forked) thread. http://bugs.python.org/issue874900
15651568
global _active_limbo_lock, _main_thread
15661569
global _shutdown_locks_lock, _shutdown_locks
1567-
_active_limbo_lock = _allocate_lock()
1570+
_active_limbo_lock = RLock()
15681571

15691572
# fork() only copied the current thread; clear references to others.
15701573
new_active = {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The :func:`threading.enumerate` function now uses a reentrant lock to
2+
prevent a hang on reentrant call.
3+
Patch by Victor Stinner.

0 commit comments

Comments
 (0)