Commit 95cd5c0b authored by Gregory P. Smith's avatar Gregory P. Smith

- Fix Issue #1703448: A joined thread could show up in the

  threading.enumerate() list after the join() for a brief period until
  it actually exited.
parent 64c5677d
...@@ -236,6 +236,24 @@ class ThreadTests(unittest.TestCase): ...@@ -236,6 +236,24 @@ class ThreadTests(unittest.TestCase):
"""]) """])
self.assertEqual(rc, 42) self.assertEqual(rc, 42)
def test_enumerate_after_join(self):
# Try hard to trigger #1703448: a thread is still returned in
# threading.enumerate() after it has been join()ed.
enum = threading.enumerate
old_interval = sys.getcheckinterval()
sys.setcheckinterval(1)
try:
for i in xrange(1, 1000):
t = threading.Thread(target=lambda: None)
t.start()
t.join()
l = enum()
self.assertFalse(t in l,
"#1703448 triggered after %d trials: %s" % (i, l))
finally:
sys.setcheckinterval(old_interval)
class ThreadingExceptionTests(unittest.TestCase): class ThreadingExceptionTests(unittest.TestCase):
# A RuntimeError should be raised if Thread.start() is called # A RuntimeError should be raised if Thread.start() is called
# multiple times. # multiple times.
......
...@@ -515,11 +515,14 @@ class Thread(_Verbose): ...@@ -515,11 +515,14 @@ class Thread(_Verbose):
if __debug__: if __debug__:
self._note("%s.__bootstrap(): normal return", self) self._note("%s.__bootstrap(): normal return", self)
finally: finally:
self.__stop() with _active_limbo_lock:
try: self.__stop()
self.__delete() try:
except: # We don't call self.__delete() because it also
pass # grabs _active_limbo_lock.
del _active[_get_ident()]
except:
pass
def __stop(self): def __stop(self):
with self.__block: with self.__block:
......
...@@ -371,6 +371,10 @@ Core and builtins ...@@ -371,6 +371,10 @@ Core and builtins
- Issue #1537: Changed GeneratorExit's base class from Exception to - Issue #1537: Changed GeneratorExit's base class from Exception to
BaseException. BaseException.
- Fix Issue #1703448: A joined thread could show up in the
threading.enumerate() list after the join() for a brief period until
it actually exited.
Library Library
------- -------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment