]> granicus.if.org Git - python/commitdiff
use the with statement for locking the internal condition (closes #25362)
authorBenjamin Peterson <benjamin@python.org>
Sun, 11 Oct 2015 02:34:46 +0000 (19:34 -0700)
committerBenjamin Peterson <benjamin@python.org>
Sun, 11 Oct 2015 02:34:46 +0000 (19:34 -0700)
Patch by Nir Soffer.

Lib/threading.py

index 80f809ce2fc03da2c74532f91d77e027ecd0eae6..56a4060337c02ff91123612e462dd73240b8c82e 100644 (file)
@@ -511,12 +511,9 @@ class Event:
         that call wait() once the flag is true will not block at all.
 
         """
-        self._cond.acquire()
-        try:
+        with self._cond:
             self._flag = True
             self._cond.notify_all()
-        finally:
-            self._cond.release()
 
     def clear(self):
         """Reset the internal flag to false.
@@ -525,11 +522,8 @@ class Event:
         set the internal flag to true again.
 
         """
-        self._cond.acquire()
-        try:
+        with self._cond:
             self._flag = False
-        finally:
-            self._cond.release()
 
     def wait(self, timeout=None):
         """Block until the internal flag is true.
@@ -546,14 +540,11 @@ class Event:
         True except if a timeout is given and the operation times out.
 
         """
-        self._cond.acquire()
-        try:
+        with self._cond:
             signaled = self._flag
             if not signaled:
                 signaled = self._cond.wait(timeout)
             return signaled
-        finally:
-            self._cond.release()
 
 
 # A barrier class.  Inspired in part by the pthread_barrier_* api and