Kaydet (Commit) fa9211b1 authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Issue #22185: Fix an occasional RuntimeError in threading.Condition.wait()…

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.
...@@ -290,6 +290,7 @@ class Condition: ...@@ -290,6 +290,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()
...@@ -299,14 +300,14 @@ class Condition: ...@@ -299,14 +300,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.
......
...@@ -1518,4 +1518,5 @@ Cheng Zhang ...@@ -1518,4 +1518,5 @@ Cheng Zhang
Kai Zhu Kai Zhu
Tarek Ziadé Tarek Ziadé
Gennadiy Zlobin Gennadiy Zlobin
Doug Zongker
Peter Åstrand Peter Åstrand
...@@ -124,6 +124,10 @@ Core and Builtins ...@@ -124,6 +124,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 #22287: On UNIX, _PyTime_gettimeofday() now uses - Issue #22287: On UNIX, _PyTime_gettimeofday() now uses
clock_gettime(CLOCK_REALTIME) if available. As a side effect, Python now clock_gettime(CLOCK_REALTIME) if available. As a side effect, Python now
depends on the librt library on Solaris and on Linux (only with glibc older depends on the librt library on Solaris and on Linux (only with glibc older
......
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