mirror of https://github.com/python/cpython.git
use the with statement for locking the internal condition (closes #25362)
Patch by Nir Soffer.
This commit is contained in:
parent
b397e3b526
commit
414918a939
|
@ -511,12 +511,9 @@ def set(self):
|
|||
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.
|
||||
|
@ -525,11 +522,8 @@ def clear(self):
|
|||
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.
|
||||
|
@ -546,14 +540,11 @@ def wait(self, timeout=None):
|
|||
True except if a timeout is given and the operation times out.
|
||||
|
||||
"""
|
||||
self._cond.acquire()
|
||||
try:
|
||||
with self._cond:
|
||||
signaled = self._flag
|
||||
if not signaled:
|
||||
signaled = self._cond.wait(timeout)
|
||||
return signaled
|
||||
finally:
|
||||
self._cond.release()
|
||||
|
||||
|
||||
# A barrier class. Inspired in part by the pthread_barrier_* api and
|
||||
|
|
Loading…
Reference in New Issue