summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2021-06-15 14:14:24 (GMT)
committerGitHub <noreply@github.com>2021-06-15 14:14:24 (GMT)
commit243fd01047ddce1a7eb0f99a49732d123e942c63 (patch)
tree5985800b6c15bf0c5b2ac337fde5922a173d5aa3 /Lib/threading.py
parent1cd3d859a49b047dd08abb6f44f0539564d3525a (diff)
downloadcpython-243fd01047ddce1a7eb0f99a49732d123e942c63.zip
cpython-243fd01047ddce1a7eb0f99a49732d123e942c63.tar.gz
cpython-243fd01047ddce1a7eb0f99a49732d123e942c63.tar.bz2
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.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 6c3d49c..766011f 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 = {}