summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2005-11-23 02:19:18 (GMT)
committerBrett Cannon <bcannon@gmail.com>2005-11-23 02:19:18 (GMT)
commitcfced277da25701300b5aeb3fde0f563ed456eab (patch)
tree951f626ad3cc582497e0894bf4609c38b5006236
parent62efb93c727a4dec42bd9326ae74cf1a6800dc0b (diff)
downloadcpython-cfced277da25701300b5aeb3fde0f563ed456eab.zip
cpython-cfced277da25701300b5aeb3fde0f563ed456eab.tar.gz
cpython-cfced277da25701300b5aeb3fde0f563ed456eab.tar.bz2
Backport of patch #1314396: prevent threading.Thread.join() from blocking if a
previous call raised an exception (e.g., calling it with an illegal argument).
-rw-r--r--Lib/threading.py34
-rw-r--r--Misc/NEWS4
2 files changed, 22 insertions, 16 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 6def594..8788ee5 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -534,24 +534,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"
diff --git a/Misc/NEWS b/Misc/NEWS
index 18c0784..b551b23 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -44,6 +44,10 @@ Extension Modules
Library
-------
+- Patch #1314396: Prevent threading.Thread.join() from blocking if a previous
+ call caused an exception to be raised (e.g., calling join() with an illegal
+ argument).
+
- urllib.unquote() now handles Unicode strings correctly. Formerly, it would
either ignore the substitution or raise UnicodeDecodeError.