Commit d194b304 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #11714: Use 'with' statements to assure a Semaphore releases a

condition variable.  Original patch by Thomas Rachel.
parent 4dc385b4
......@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment