]> granicus.if.org Git - python/commitdiff
Merged revisions 78517 via svnmerge from
authorGregory P. Smith <greg@mad-scientist.com>
Sun, 28 Feb 2010 18:40:12 +0000 (18:40 +0000)
committerGregory P. Smith <greg@mad-scientist.com>
Sun, 28 Feb 2010 18:40:12 +0000 (18:40 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78517 | gregory.p.smith | 2010-02-28 10:36:09 -0800 (Sun, 28 Feb 2010) | 3 lines

  Issue #7481: When a threading.Thread failed to start it would leave the
  instance stuck in initial state and present in threading.enumerate().
........

Lib/test/test_threading.py
Lib/threading.py
Misc/NEWS

index edf74de1cc7066cd16644d87f1fd76d337e5e3b8..fe076b134f2663600cf0ae5675750d5d50d50899 100644 (file)
@@ -219,6 +219,25 @@ class ThreadTests(unittest.TestCase):
             t.join()
         # else the thread is still running, and we have no way to kill it
 
+    def test_limbo_cleanup(self):
+        # Issue 7481: Failure to start thread should cleanup the limbo map.
+        def fail_new_thread(*args):
+            raise thread.error()
+        _start_new_thread = threading._start_new_thread
+        threading._start_new_thread = fail_new_thread
+        try:
+            t = threading.Thread(target=lambda: None)
+            try:
+                t.start()
+                assert False
+            except thread.error:
+                self.assertFalse(
+                    t in threading._limbo,
+                    "Failed to cleanup _limbo map on failure of Thread.start()."
+                )
+        finally:
+            threading._start_new_thread = _start_new_thread
+
     def test_finalize_runnning_thread(self):
         # Issue 1402: the PyGILState_Ensure / _Release functions may be called
         # very late on python exit: on deallocation of a running thread for
index 15c5f2931551c235a932f120124608855d1e6a85..ee70cd86334d6654b68ac81b54b7701838f6b7fa 100644 (file)
@@ -470,7 +470,12 @@ class Thread(_Verbose):
         _active_limbo_lock.acquire()
         _limbo[self] = self
         _active_limbo_lock.release()
-        _start_new_thread(self.__bootstrap, ())
+        try:
+            _start_new_thread(self.__bootstrap, ())
+        except Exception:
+            with _active_limbo_lock:
+                del _limbo[self]
+            raise
         self.__started.wait()
 
     def run(self):
index e68d1ce83e3c54b119c7f5769227275ad9e47416..c2a124739499d78fe9f96f72a9d303b92b796962 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -232,6 +232,9 @@ Library
 - Issue #5037: Proxy the __unicode__ special method to __unicode__ instead of
   __str__.
 
+- Issue #7481: When a threading.Thread failed to start it would leave the
+  instance stuck in initial state and present in threading.enumerate().
+
 Extension Modules
 -----------------