Kaydet (Commit) b00b596c authored tarafından Serhiy Storchaka's avatar Serhiy Storchaka

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

condition variable.  Original patch by Thomas Rachel.
......@@ -253,31 +253,29 @@ class Semaphore:
raise ValueError("can't specify timeout for non-blocking acquire")
rc = False
endtime = None
self._cond.acquire()
while self._value == 0:
if not blocking:
break
if timeout is not None:
if endtime is None:
endtime = _time() + timeout
else:
timeout = endtime - _time()
if timeout <= 0:
break
self._cond.wait(timeout)
else:
self._value -= 1
rc = True
self._cond.release()
with self._cond:
while self._value == 0:
if not blocking:
break
if timeout is not None:
if endtime is None:
endtime = _time() + timeout
else:
timeout = endtime - _time()
if timeout <= 0:
break
self._cond.wait(timeout)
else:
self._value -= 1
rc = True
return rc
__enter__ = acquire
def release(self):
self._cond.acquire()
self._value += 1
self._cond.notify()
self._cond.release()
with self._cond:
self._value += 1
self._cond.notify()
def __exit__(self, t, v, tb):
self.release()
......
......@@ -993,6 +993,7 @@ Fernando Pérez
Pierre Quentel
Brian Quinlan
Anders Qvist
Thomas Rachel
Ram Rachum
Jérôme Radix
Burton Radons
......
......@@ -49,6 +49,9 @@ Core and Builtins
Library
-------
- Issue #11714: Use 'with' statements to assure a Semaphore releases a
condition variable. Original patch by Thomas Rachel.
- Issue #16624: `subprocess.check_output` now accepts an `input` argument,
allowing the subprocess's stdin to be provided as a (byte) string.
Patch by Zack Weinberg.
......
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