]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 76117 via svnmerge from
authorAntoine Pitrou <solipsis@pitrou.net>
Thu, 5 Nov 2009 13:44:28 +0000 (13:44 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Thu, 5 Nov 2009 13:44:28 +0000 (13:44 +0000)
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 #7264: Fix a possible deadlock when deallocating thread-local objects
  which are part of a reference cycle.
........

Lib/_threading_local.py
Lib/threading.py
Misc/NEWS

index 4eda630bbdcf564dca2d36b21edf840e0af000a6..243d84ef7caf08fa14c083045e993dc8bf812332 100644 (file)
@@ -218,10 +218,12 @@ class local(_localbase):
         key = object.__getattribute__(self, '_local__key')
 
         try:
-            threads = list(threading.enumerate())
+            # We use the non-locking API since we might already hold the lock
+            # (__del__ can be called at any point by the cyclic GC).
+            threads = threading._enumerate()
         except:
-            # If enumerate fails, as it seems to do during
-            # shutdown, we'll skip cleanup under the assumption
+            # If enumerating the current threads fails, as it seems to do
+            # during shutdown, we'll skip cleanup under the assumption
             # that there is nothing to clean up.
             return
 
index 1182f1922690572c7a988512b270de3c0caa873b..18c28b7ffa42e3f95194f94e8390f597682b5571 100644 (file)
@@ -815,6 +815,10 @@ def activeCount():
 
 active_count = activeCount
 
+def _enumerate():
+    # Same as enumerate(), but without the lock. Internal use only.
+    return _active.values() + _limbo.values()
+
 def enumerate():
     _active_limbo_lock.acquire()
     active = _active.values() + _limbo.values()
index 7bcad726295c02f5fbb5189e04fd8d68bf57347b..71d613bf6f9b0c92b1bfde78758cc7554f61b40e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -24,6 +24,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #7264: Fix a possible deadlock when deallocating thread-local objects
+  which are part of a reference cycle.
+
 - Issue #7249: Methods of io.BytesIO now allow `long` as well as `int`
   arguments.