mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
1cd3d859a4
commit
243fd01047
2 changed files with 9 additions and 3 deletions
|
@ -775,8 +775,11 @@ _counter = _count(1).__next__
|
||||||
def _newname(name_template):
|
def _newname(name_template):
|
||||||
return name_template % _counter()
|
return name_template % _counter()
|
||||||
|
|
||||||
# Active thread administration
|
# Active thread administration.
|
||||||
_active_limbo_lock = _allocate_lock()
|
#
|
||||||
|
# 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
|
_active = {} # maps thread id to Thread object
|
||||||
_limbo = {}
|
_limbo = {}
|
||||||
_dangling = WeakSet()
|
_dangling = WeakSet()
|
||||||
|
@ -1564,7 +1567,7 @@ def _after_fork():
|
||||||
# by another (non-forked) thread. http://bugs.python.org/issue874900
|
# by another (non-forked) thread. http://bugs.python.org/issue874900
|
||||||
global _active_limbo_lock, _main_thread
|
global _active_limbo_lock, _main_thread
|
||||||
global _shutdown_locks_lock, _shutdown_locks
|
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.
|
# fork() only copied the current thread; clear references to others.
|
||||||
new_active = {}
|
new_active = {}
|
||||||
|
|
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue