diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-04-22 19:51:00 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-04-22 19:51:00 (GMT) |
commit | d194b30407bee1f38ad77f32dca3880853a6a308 (patch) | |
tree | 6f5650227734ba45596c47285119997ccb94f723 | |
parent | 4dc385b4e3a9f7c140ac9725f85d0e60ccce66e6 (diff) | |
download | cpython-d194b30407bee1f38ad77f32dca3880853a6a308.zip cpython-d194b30407bee1f38ad77f32dca3880853a6a308.tar.gz cpython-d194b30407bee1f38ad77f32dca3880853a6a308.tar.bz2 |
Issue #11714: Use 'with' statements to assure a Semaphore releases a
condition variable. Original patch by Thomas Rachel.
-rw-r--r-- | Lib/threading.py | 42 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 24 insertions, 22 deletions
diff --git a/Lib/threading.py b/Lib/threading.py index cb49c4a..225448b 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -457,21 +457,20 @@ class _Semaphore(_Verbose): """ rc = False - self.__cond.acquire() - while self.__value == 0: - if not blocking: - break - if __debug__: - self._note("%s.acquire(%s): blocked waiting, value=%s", - self, blocking, self.__value) - self.__cond.wait() - else: - self.__value = self.__value - 1 - if __debug__: - self._note("%s.acquire: success, value=%s", - self, self.__value) - rc = True - self.__cond.release() + with self.__cond: + while self.__value == 0: + if not blocking: + break + if __debug__: + self._note("%s.acquire(%s): blocked waiting, value=%s", + self, blocking, self.__value) + self.__cond.wait() + else: + self.__value = self.__value - 1 + if __debug__: + self._note("%s.acquire: success, value=%s", + self, self.__value) + rc = True return rc __enter__ = acquire @@ -483,13 +482,12 @@ class _Semaphore(_Verbose): to become larger than zero again, wake up that thread. """ - self.__cond.acquire() - self.__value = self.__value + 1 - if __debug__: - self._note("%s.release: success, value=%s", - self, self.__value) - self.__cond.notify() - self.__cond.release() + with self.__cond: + self.__value = self.__value + 1 + if __debug__: + self._note("%s.release: success, value=%s", + self, self.__value) + self.__cond.notify() def __exit__(self, t, v, tb): self.release() @@ -810,6 +810,7 @@ Fernando Pérez Eduardo Pérez Brian Quinlan Anders Qvist +Thomas Rachel Burton Radons Jeff Ramnani Brodie Rao @@ -28,6 +28,9 @@ Core and Builtins Library ------- +- Issue #11714: Use 'with' statements to assure a Semaphore releases a + condition variable. Original patch by Thomas Rachel. + - Issue #17795: Reverted backwards-incompatible change in SysLogHandler with Unix domain sockets. |