]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44422: Fix threading.enumerate() reentrant call (GH-26727)
authorVictor Stinner <vstinner@python.org>
Tue, 15 Jun 2021 14:14:24 +0000 (16:14 +0200)
committerGitHub <noreply@github.com>
Tue, 15 Jun 2021 14:14:24 +0000 (16:14 +0200)
The threading.enumerate() function now uses a reentrant lock to
prevent a hang on reentrant call.

Lib/threading.py
Misc/NEWS.d/next/Library/2021-06-14-23-28-17.bpo-44422.BlWOgv.rst [new file with mode: 0644]

index 6c3d49c2d52679fdfdd4f5ea1f92fe1e052df761..766011fa0312b34e01c534c89de9defd62ed56c6 100644 (file)
@@ -775,8 +775,11 @@ _counter = _count(1).__next__
 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()
@@ -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 = {}
diff --git a/Misc/NEWS.d/next/Library/2021-06-14-23-28-17.bpo-44422.BlWOgv.rst b/Misc/NEWS.d/next/Library/2021-06-14-23-28-17.bpo-44422.BlWOgv.rst
new file mode 100644 (file)
index 0000000..09bace0
--- /dev/null
@@ -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.