summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2011-01-04 18:42:29 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2011-01-04 18:42:29 (GMT)
commitdb0ef2b5e51b393736f20e81d23d68c9b92a04b4 (patch)
tree844f65fd07b65b352e4bdcc6c1603d10dbd66883 /Lib/threading.py
parent4b129d23f66f88fb91aa95d163ef55a47095ae0d (diff)
downloadcpython-db0ef2b5e51b393736f20e81d23d68c9b92a04b4.zip
cpython-db0ef2b5e51b393736f20e81d23d68c9b92a04b4.tar.gz
cpython-db0ef2b5e51b393736f20e81d23d68c9b92a04b4.tar.bz2
Merged revisions 87740 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r87740 | gregory.p.smith | 2011-01-04 10:33:38 -0800 (Tue, 04 Jan 2011) | 6 lines 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. ........
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 76c729b..c965c6f 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -358,6 +358,10 @@ class _Event(_Verbose):
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
@@ -434,6 +438,13 @@ class Thread(_Verbose):
# 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
@@ -776,12 +787,11 @@ class _DummyThread(Thread):
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:
@@ -858,8 +868,7 @@ def _after_fork():
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.