summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-11-21 21:08:39 (GMT)
committerGuido van Rossum <guido@python.org>2002-11-21 21:08:39 (GMT)
commit21b60147e9d4e6c895b581429d292cb60bcdb5e7 (patch)
tree8e83787b67de1824bc5480b4e025dd327da25afb /Lib/threading.py
parentd584368dec1fd74e7bc1a72dec2d50172aa1278e (diff)
downloadcpython-21b60147e9d4e6c895b581429d292cb60bcdb5e7.zip
cpython-21b60147e9d4e6c895b581429d292cb60bcdb5e7.tar.gz
cpython-21b60147e9d4e6c895b581429d292cb60bcdb5e7.tar.bz2
The _Event class should be more careful with releasing its lock when
interrupted. A try/finally will do nicely. Maybe other classes need this too, but since they manipulate more state it's less clear that that is always the right thing, and I'm in a hurry. Backport candidate.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index f949d75..1e769a8 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -318,20 +318,26 @@ class _Event(_Verbose):
def set(self):
self.__cond.acquire()
- self.__flag = True
- self.__cond.notifyAll()
- self.__cond.release()
+ try:
+ self.__flag = True
+ self.__cond.notifyAll()
+ finally:
+ self.__cond.release()
def clear(self):
self.__cond.acquire()
- self.__flag = False
- self.__cond.release()
+ try:
+ self.__flag = False
+ finally:
+ self.__cond.release()
def wait(self, timeout=None):
self.__cond.acquire()
- if not self.__flag:
- self.__cond.wait(timeout)
- self.__cond.release()
+ try:
+ if not self.__flag:
+ self.__cond.wait(timeout)
+ finally:
+ self.__cond.release()
# Helper to generate new thread names
_counter = 0