mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
Issue #22185: Fix an occasional RuntimeError in threading.Condition.wait() caused by mutation of the waiters queue without holding the lock.
Patch by Doug Zongker.
This commit is contained in:
commit
fa9211b11d
3 changed files with 11 additions and 5 deletions
|
|
@ -290,6 +290,7 @@ def wait(self, timeout=None):
|
|||
waiter.acquire()
|
||||
self._waiters.append(waiter)
|
||||
saved_state = self._release_save()
|
||||
gotit = False
|
||||
try: # restore state no matter what (e.g., KeyboardInterrupt)
|
||||
if timeout is None:
|
||||
waiter.acquire()
|
||||
|
|
@ -299,14 +300,14 @@ def wait(self, timeout=None):
|
|||
gotit = waiter.acquire(True, timeout)
|
||||
else:
|
||||
gotit = waiter.acquire(False)
|
||||
if not gotit:
|
||||
try:
|
||||
self._waiters.remove(waiter)
|
||||
except ValueError:
|
||||
pass
|
||||
return gotit
|
||||
finally:
|
||||
self._acquire_restore(saved_state)
|
||||
if not gotit:
|
||||
try:
|
||||
self._waiters.remove(waiter)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def wait_for(self, predicate, timeout=None):
|
||||
"""Wait until a condition evaluates to True.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue