mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +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:
parent
6685883c02
commit
a64b92edd3
3 changed files with 11 additions and 5 deletions
|
@ -284,6 +284,7 @@ class Condition:
|
||||||
waiter.acquire()
|
waiter.acquire()
|
||||||
self._waiters.append(waiter)
|
self._waiters.append(waiter)
|
||||||
saved_state = self._release_save()
|
saved_state = self._release_save()
|
||||||
|
gotit = False
|
||||||
try: # restore state no matter what (e.g., KeyboardInterrupt)
|
try: # restore state no matter what (e.g., KeyboardInterrupt)
|
||||||
if timeout is None:
|
if timeout is None:
|
||||||
waiter.acquire()
|
waiter.acquire()
|
||||||
|
@ -293,14 +294,14 @@ class Condition:
|
||||||
gotit = waiter.acquire(True, timeout)
|
gotit = waiter.acquire(True, timeout)
|
||||||
else:
|
else:
|
||||||
gotit = waiter.acquire(False)
|
gotit = waiter.acquire(False)
|
||||||
if not gotit:
|
|
||||||
try:
|
|
||||||
self._waiters.remove(waiter)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
return gotit
|
return gotit
|
||||||
finally:
|
finally:
|
||||||
self._acquire_restore(saved_state)
|
self._acquire_restore(saved_state)
|
||||||
|
if not gotit:
|
||||||
|
try:
|
||||||
|
self._waiters.remove(waiter)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
def wait_for(self, predicate, timeout=None):
|
def wait_for(self, predicate, timeout=None):
|
||||||
"""Wait until a condition evaluates to True.
|
"""Wait until a condition evaluates to True.
|
||||||
|
|
|
@ -1500,4 +1500,5 @@ Cheng Zhang
|
||||||
Kai Zhu
|
Kai Zhu
|
||||||
Tarek Ziadé
|
Tarek Ziadé
|
||||||
Gennadiy Zlobin
|
Gennadiy Zlobin
|
||||||
|
Doug Zongker
|
||||||
Peter Åstrand
|
Peter Åstrand
|
||||||
|
|
|
@ -27,6 +27,10 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- 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.
|
||||||
|
|
||||||
- Issue #22182: Use e.args to unpack exceptions correctly in
|
- Issue #22182: Use e.args to unpack exceptions correctly in
|
||||||
distutils.file_util.move_file. Patch by Claudiu Popa.
|
distutils.file_util.move_file. Patch by Claudiu Popa.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue