summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-10-11 02:34:46 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-10-11 02:34:46 (GMT)
commit414918a939b02aa3f7048ba341a3f6862ab9a71e (patch)
treef52d5d7a768e191548de9fa9a79f690d9f2bc372
parentb397e3b526bc18eba9aa6ded2d53d9be51eb552d (diff)
downloadcpython-414918a939b02aa3f7048ba341a3f6862ab9a71e.zip
cpython-414918a939b02aa3f7048ba341a3f6862ab9a71e.tar.gz
cpython-414918a939b02aa3f7048ba341a3f6862ab9a71e.tar.bz2
use the with statement for locking the internal condition (closes #25362)
Patch by Nir Soffer.
-rw-r--r--Lib/threading.py15
1 files changed, 3 insertions, 12 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 80f809c..56a4060 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -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