From: Benjamin Peterson Date: Sun, 11 Oct 2015 02:34:46 +0000 (-0700) Subject: use the with statement for locking the internal condition (closes #25362) X-Git-Tag: v2.7.11rc1~69 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5f32b236f1f048b4a03dc677466cbdb15e1843de;p=thirdparty%2FPython%2Fcpython.git use the with statement for locking the internal condition (closes #25362) Patch by Nir Soffer. --- diff --git a/Lib/threading.py b/Lib/threading.py index 51205fa8258d..527f20acc60c 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