[Python-checkins] r87740 - python/branches/py3k/Lib/threading.py

gregory.p.smith python-checkins at python.org
Tue Jan 4 19:33:38 CET 2011


Author: gregory.p.smith
Date: Tue Jan  4 19:33:38 2011
New Revision: 87740

Log:
Fix the new bug introduced in the r87710 fix for issue 6643.  DummyThread
deletes its _block attribute, deal with that.  This prevents an uncaught
exception in a thread during test_thread.

This refactors a bit to better match what I did in the r87727 backport to 2.7.


Modified:
   python/branches/py3k/Lib/threading.py

Modified: python/branches/py3k/Lib/threading.py
==============================================================================
--- python/branches/py3k/Lib/threading.py	(original)
+++ python/branches/py3k/Lib/threading.py	Tue Jan  4 19:33:38 2011
@@ -395,6 +395,10 @@
         self._cond = Condition(Lock())
         self._flag = False
 
+    def _reset_internal_locks(self):
+        # private!  called by Thread._reset_internal_locks by _after_fork()
+        self._cond.__init__()
+
     def is_set(self):
         return self._flag
 
@@ -642,6 +646,13 @@
         # sys.exc_info since it can be changed between instances
         self._stderr = _sys.stderr
 
+    def _reset_internal_locks(self):
+        # private!  Called by _after_fork() to reset our internal locks as
+        # they may be in an invalid state leading to a deadlock or crash.
+        if hasattr(self, '_block'):  # DummyThread deletes _block
+            self._block.__init__()
+        self._started._reset_internal_locks()
+
     def _set_daemon(self):
         # Overridden in _MainThread and _DummyThread
         return current_thread().daemon
@@ -984,12 +995,11 @@
     def __init__(self):
         Thread.__init__(self, name=_newname("Dummy-%d"))
 
-        # Thread.__block consumes an OS-level locking primitive, which
+        # Thread._block consumes an OS-level locking primitive, which
         # can never be used by a _DummyThread.  Since a _DummyThread
         # instance is immortal, that's bad, so release this resource.
         del self._block
 
-
         self._started.set()
         self._set_ident()
         with _active_limbo_lock:
@@ -1066,8 +1076,7 @@
                 thread._ident = ident
                 # Any condition variables hanging off of the active thread may
                 # be in an invalid state, so we reinitialize them.
-                thread._block.__init__()
-                thread._started._cond.__init__()
+                thread._reset_internal_locks()
                 new_active[ident] = thread
             else:
                 # All the others are already stopped.


More information about the Python-checkins mailing list