Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit db0ef2b

Browse files
committed
Merged revisions 87740 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent 4b129d2 commit db0ef2b

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

Lib/threading.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ def __init__(self, verbose=None):
358358
self._cond = Condition(Lock())
359359
self._flag = False
360360

361+
def _reset_internal_locks(self):
362+
# private! called by Thread._reset_internal_locks by _after_fork()
363+
self._cond.__init__()
364+
361365
def is_set(self):
362366
return self._flag
363367

@@ -434,6 +438,13 @@ def __init__(self, group=None, target=None, name=None,
434438
# sys.exc_info since it can be changed between instances
435439
self._stderr = _sys.stderr
436440

441+
def _reset_internal_locks(self):
442+
# private! Called by _after_fork() to reset our internal locks as
443+
# they may be in an invalid state leading to a deadlock or crash.
444+
if hasattr(self, '_block'): # DummyThread deletes _block
445+
self._block.__init__()
446+
self._started._reset_internal_locks()
447+
437448
def _set_daemon(self):
438449
# Overridden in _MainThread and _DummyThread
439450
return current_thread().daemon
@@ -776,12 +787,11 @@ class _DummyThread(Thread):
776787
def __init__(self):
777788
Thread.__init__(self, name=_newname("Dummy-%d"))
778789

779-
# Thread.__block consumes an OS-level locking primitive, which
790+
# Thread._block consumes an OS-level locking primitive, which
780791
# can never be used by a _DummyThread. Since a _DummyThread
781792
# instance is immortal, that's bad, so release this resource.
782793
del self._block
783794

784-
785795
self._started.set()
786796
self._set_ident()
787797
with _active_limbo_lock:
@@ -858,8 +868,7 @@ def _after_fork():
858868
thread._ident = ident
859869
# Any condition variables hanging off of the active thread may
860870
# be in an invalid state, so we reinitialize them.
861-
thread._block.__init__()
862-
thread._started._cond.__init__()
871+
thread._reset_internal_locks()
863872
new_active[ident] = thread
864873
else:
865874
# All the others are already stopped.

0 commit comments

Comments
 (0)