summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-06-15 07:34:42 -0700
committerGitHub <noreply@github.com>2021-06-15 07:34:42 -0700
commitc3b776f83b4c765da6d7b8854e844e07bd33c375 (patch)
tree4e9bd562324585032743a77f9f522ab94eb58d20
parente30fe27dabbc6b48736c3c17d57f6fa542376e8f (diff)
downloadcpython-git-c3b776f83b4c765da6d7b8854e844e07bd33c375.tar.gz
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. (cherry picked from commit 243fd01047ddce1a7eb0f99a49732d123e942c63) Co-authored-by: Victor Stinner <vstinner@python.org>
-rw-r--r--Lib/threading.py9
-rw-r--r--Misc/NEWS.d/next/Library/2021-06-14-23-28-17.bpo-44422.BlWOgv.rst3
2 files changed, 9 insertions, 3 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 6c3d49c2d5..766011fa03 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -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
index 0000000000..09bace01fc
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-06-14-23-28-17.bpo-44422.BlWOgv.rst
@@ -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.