Skip to content

[3.10] bpo-44422: Fix threading.enumerate() reentrant call (GH-26727) #26737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,8 +775,11 @@ class BrokenBarrierError(RuntimeError):
def _newname(name_template):
return name_template % _counter()

# Active thread administration
_active_limbo_lock = _allocate_lock()
# Active thread administration.
#
# bpo-44422: Use a reentrant lock to allow reentrant calls to functions like
# threading.enumerate().
_active_limbo_lock = RLock()
_active = {} # maps thread id to Thread object
_limbo = {}
_dangling = WeakSet()
Expand Down Expand Up @@ -1564,7 +1567,7 @@ def _after_fork():
# by another (non-forked) thread. http://bugs.python.org/issue874900
global _active_limbo_lock, _main_thread
global _shutdown_locks_lock, _shutdown_locks
_active_limbo_lock = _allocate_lock()
_active_limbo_lock = RLock()

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