diff options
author | Jeffrey Yasskin <jyasskin@gmail.com> | 2008-03-28 04:11:18 (GMT) |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@gmail.com> | 2008-03-28 04:11:18 (GMT) |
commit | 8b9091fba07b813b7486ef8fef279f2bf950570b (patch) | |
tree | 7dd25f52ebbe7c8276901a03bad5d651e693845c /Lib/threading.py | |
parent | 7db15fe9d9f42b73b8dad4d13965259de2eea09f (diff) | |
download | cpython-8b9091fba07b813b7486ef8fef279f2bf950570b.zip cpython-8b9091fba07b813b7486ef8fef279f2bf950570b.tar.gz cpython-8b9091fba07b813b7486ef8fef279f2bf950570b.tar.bz2 |
Kill a race in test_threading in which the exception info in a thread finishing
up after it was joined had a traceback pointing to that thread's (deleted)
target attribute, while the test was trying to check that the target was
destroyed. Big thanks to Antoine Pitrou for diagnosing the race and pointing
out sys.exc_clear() to kill the exception early. This fixes issue 2496.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r-- | Lib/threading.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/threading.py b/Lib/threading.py index 86153b0..eebe10a 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -392,6 +392,9 @@ class Thread(_Verbose): # shutdown and thus raises an exception about trying to perform some # operation on/with a NoneType __exc_info = _sys.exc_info + # Keep sys.exc_clear too to clear the exception just before + # allowing .join() to return. + __exc_clear = _sys.exc_clear def __init__(self, group=None, target=None, name=None, args=(), kwargs=None, verbose=None): @@ -527,6 +530,12 @@ class Thread(_Verbose): else: if __debug__: self._note("%s.__bootstrap(): normal return", self) + finally: + # Prevent a race in + # test_threading.test_no_refcycle_through_target when + # the exception keeps the target alive past when we + # assert that it's dead. + self.__exc_clear() finally: with _active_limbo_lock: self.__stop() |