]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport:
authorNeal Norwitz <nnorwitz@gmail.com>
Sun, 2 Feb 2003 19:24:38 +0000 (19:24 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Sun, 2 Feb 2003 19:24:38 +0000 (19:24 +0000)
revision 1.29
date: 2002/11/21 21:08:39;  author: gvanrossum;  state: Exp;  lines: +14 -8
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.

Lib/threading.py

index 9763c629d8d25687dd1afedbdf8ac5b49643de90..ffbeb0ed618e356cf620c8b7a19cc10f308c054f 100644 (file)
@@ -316,20 +316,26 @@ class _Event(_Verbose):
 
     def set(self):
         self.__cond.acquire()
-        self.__flag = 1
-        self.__cond.notifyAll()
-        self.__cond.release()
+        try:
+            self.__flag = 1
+            self.__cond.notifyAll()
+        finally:
+            self.__cond.release()
 
     def clear(self):
         self.__cond.acquire()
-        self.__flag = 0
-        self.__cond.release()
+        try:
+            self.__flag = 0
+        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