Skip to content

Commit 8fe57aa

Browse files
bpo-44422: Fix threading.enumerate() reentrant call (GH-26727) (GH-26738)
The threading.enumerate() function now uses a reentrant lock to prevent a hang on reentrant call. (cherry picked from commit 243fd01) Co-authored-by: Victor Stinner <[email protected]>
1 parent 0d0a9ea commit 8fe57aa

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
@@ -750,8 +750,11 @@ class BrokenBarrierError(RuntimeError):
750750
def _newname(template="Thread-%d"):
751751
return template % _counter()
752752

753-
# Active thread administration
754-
_active_limbo_lock = _allocate_lock()
753+
# Active thread administration.
754+
#
755+
# bpo-44422: Use a reentrant lock to allow reentrant calls to functions like
756+
# threading.enumerate().
757+
_active_limbo_lock = RLock()
755758
_active = {} # maps thread id to Thread object
756759
_limbo = {}
757760
_dangling = WeakSet()
@@ -1474,7 +1477,7 @@ def _after_fork():
14741477
# by another (non-forked) thread. http://bugs.python.org/issue874900
14751478
global _active_limbo_lock, _main_thread
14761479
global _shutdown_locks_lock, _shutdown_locks
1477-
_active_limbo_lock = _allocate_lock()
1480+
_active_limbo_lock = RLock()
14781481

14791482
# fork() only copied the current thread; clear references to others.
14801483
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)