]> granicus.if.org Git - python/commitdiff
Prevent threading.Thread.join() from blocking when a previous call raised an
authorBrett Cannon <bcannon@gmail.com>
Wed, 23 Nov 2005 02:15:50 +0000 (02:15 +0000)
committerBrett Cannon <bcannon@gmail.com>
Wed, 23 Nov 2005 02:15:50 +0000 (02:15 +0000)
exception (e.g., passing in an illegal argument).

Applies patch #1314396.  Thanks Eric Blossom.

Lib/threading.py
Misc/ACKS
Misc/NEWS

index fe4490fa3ac399a1318053577bde2fe723eb65dd..9cc108e08731805fec4825f6b0d3042c2b9366ac 100644 (file)
@@ -536,24 +536,26 @@ class Thread(_Verbose):
             if not self.__stopped:
                 self._note("%s.join(): waiting until thread stops", self)
         self.__block.acquire()
-        if timeout is None:
-            while not self.__stopped:
-                self.__block.wait()
-            if __debug__:
-                self._note("%s.join(): thread stopped", self)
-        else:
-            deadline = _time() + timeout
-            while not self.__stopped:
-                delay = deadline - _time()
-                if delay <= 0:
-                    if __debug__:
-                        self._note("%s.join(): timed out", self)
-                    break
-                self.__block.wait(delay)
-            else:
+        try:
+            if timeout is None:
+                while not self.__stopped:
+                    self.__block.wait()
                 if __debug__:
                     self._note("%s.join(): thread stopped", self)
-        self.__block.release()
+            else:
+                deadline = _time() + timeout
+                while not self.__stopped:
+                    delay = deadline - _time()
+                    if delay <= 0:
+                        if __debug__:
+                            self._note("%s.join(): timed out", self)
+                        break
+                    self.__block.wait(delay)
+                else:
+                    if __debug__:
+                        self._note("%s.join(): thread stopped", self)
+        finally:
+            self.__block.release()
 
     def getName(self):
         assert self.__initialized, "Thread.__init__() not called"
index 72ed346fc57e24118d4142337291d63fa4a1ee16..8eebc053f8a90bb9f3a423213871940689829619 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -63,6 +63,7 @@ Roy Bixler
 Martin Bless
 Pablo Bleyer
 Erik van Blokland
+Eric Blossom
 Finn Bock
 Paul Boddie
 Matthew Boedicker
index 955015602ec40aab12d78b868f7aef4a766fcf1b..73171f3031be718bf46ee474b11d958e5c52e18f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -284,6 +284,10 @@ Extension Modules
 Library
 -------
 
+- Patch #1314396: prevent deadlock for threading.Thread.join() when an exception
+  is raised within the method itself on a previous call (e.g., passing in an
+  illegal argument)
+
 - Bug #1340337: change time.strptime() to always return ValueError when there
   is an error in the format string.