summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@mad-scientist.com>2011-01-04 01:10:08 (GMT)
committerGregory P. Smith <greg@mad-scientist.com>2011-01-04 01:10:08 (GMT)
commit2b79a8146155579bf2ea8acdd4237bc58554dbb8 (patch)
tree6e7ee72048556294db3d57d0006d58a8ff338c6c /Lib/threading.py
parent7247d67e87b0f0c50f1bcf0a134a82373606f40c (diff)
downloadcpython-2b79a8146155579bf2ea8acdd4237bc58554dbb8.zip
cpython-2b79a8146155579bf2ea8acdd4237bc58554dbb8.tar.gz
cpython-2b79a8146155579bf2ea8acdd4237bc58554dbb8.tar.bz2
Merged revisions 87710 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r87710 | gregory.p.smith | 2011-01-03 13:06:12 -0800 (Mon, 03 Jan 2011) | 4 lines issue6643 - Two locks held within the threading module on each thread instance needed to be reinitialized after fork(). Adds tests to confirm that they are and that a potential deadlock and crasher bug are fixed (platform dependant). ........ This required a bit more fiddling for 2.x as __block and __started are __ private as well as the __started Event's __cond. A new "private" _reset_internal_locks() method is added to Thread and _Event objects to address this.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 5ac45e1..b05597d 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -373,6 +373,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 isSet(self):
return self.__flag
@@ -449,6 +453,17 @@ 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.
+ self.__block.__init__()
+ self.__started._reset_internal_locks()
+
+ @property
+ def _block(self):
+ # used by a unittest
+ return self.__block
+
def _set_daemon(self):
# Overridden in _MainThread and _DummyThread
return current_thread().daemon
@@ -867,6 +882,9 @@ def _after_fork():
# its new value since it can have changed.
ident = _get_ident()
thread._Thread__ident = ident
+ # Any condition variables hanging off of the active thread may
+ # be in an invalid state, so we reinitialize them.
+ thread._reset_internal_locks()
new_active[ident] = thread
else:
# All the others are already stopped.