summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
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)
commit5f32b236f1f048b4a03dc677466cbdb15e1843de (patch)
tree6c815f0aadcdbb33a0bdc68a93304c8d92c6bbe2 /Lib/threading.py
parent4ed35fc4f31ebbdb25ba5e1291de77f4095c33d0 (diff)
downloadcpython-5f32b236f1f048b4a03dc677466cbdb15e1843de.zip
cpython-5f32b236f1f048b4a03dc677466cbdb15e1843de.tar.gz
cpython-5f32b236f1f048b4a03dc677466cbdb15e1843de.tar.bz2
use the with statement for locking the internal condition (closes #25362)
Patch by Nir Soffer.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py15
1 files changed, 3 insertions, 12 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index 51205fa..527f20a 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -580,12 +580,9 @@ class _Event(_Verbose):
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.
@@ -594,11 +591,8 @@ class _Event(_Verbose):
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.
@@ -615,13 +609,10 @@ class _Event(_Verbose):
True except if a timeout is given and the operation times out.
"""
- self.__cond.acquire()
- try:
+ with self.__cond:
if not self.__flag:
self.__cond.wait(timeout)
return self.__flag
- finally:
- self.__cond.release()
# Helper to generate new thread names
_counter = _count().next