]> granicus.if.org Git - python/commitdiff
The _Event class should be more careful with releasing its lock when
authorGuido van Rossum <guido@python.org>
Thu, 21 Nov 2002 21:08:39 +0000 (21:08 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 21 Nov 2002 21:08:39 +0000 (21:08 +0000)
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.

Lib/threading.py

index f949d75598cdb92bf2db654741472793e09d52c5..1e769a87976cdc469286348f2849bd8dd24d24f8 100644 (file)
@@ -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