Skip to content

Commit bdec11f

Browse files
committed
Merged revisions 76117 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r76117 | antoine.pitrou | 2009-11-05 14:42:29 +0100 (jeu., 05 nov. 2009) | 5 lines Issue python#7264: Fix a possible deadlock when deallocating thread-local objects which are part of a reference cycle. ........
1 parent cfed029 commit bdec11f

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎Lib/_threading_local.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,12 @@ def __del__(self):
217217
key = object.__getattribute__(self, '_local__key')
218218

219219
try:
220-
threads = list(threading.enumerate())
220+
# We use the non-locking API since we might already hold the lock
221+
# (__del__ can be called at any point by the cyclic GC).
222+
threads = threading._enumerate()
221223
except:
222-
# If enumerate fails, as it seems to do during
223-
# shutdown, we'll skip cleanup under the assumption
224+
# If enumerating the current threads fails, as it seems to do
225+
# during shutdown, we'll skip cleanup under the assumption
224226
# that there is nothing to clean up.
225227
return
226228

‎Lib/threading.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,10 @@ def active_count():
798798

799799
activeCount = active_count
800800

801+
def _enumerate():
802+
# Same as enumerate(), but without the lock. Internal use only.
803+
return list(_active.values()) + list(_limbo.values())
804+
801805
def enumerate():
802806
with _active_limbo_lock:
803807
return list(_active.values()) + list(_limbo.values())

‎Misc/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ C-API
123123
Library
124124
-------
125125

126+
- Issue #7264: Fix a possible deadlock when deallocating thread-local objects
127+
which are part of a reference cycle.
128+
126129
- Issue #7211: Allow 64-bit values for the `ident` and `data` fields of kevent
127130
objects on 64-bit systems. Patch by Michael Broghton.
128131

0 commit comments

Comments
 (0)