Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fa9211b

Browse files
committed
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.
2 parents 67ca33d + a64b92e commit fa9211b

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

Lib/threading.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ def wait(self, timeout=None):
290290
waiter.acquire()
291291
self._waiters.append(waiter)
292292
saved_state = self._release_save()
293+
gotit = False
293294
try: # restore state no matter what (e.g., KeyboardInterrupt)
294295
if timeout is None:
295296
waiter.acquire()
@@ -299,14 +300,14 @@ def wait(self, timeout=None):
299300
gotit = waiter.acquire(True, timeout)
300301
else:
301302
gotit = waiter.acquire(False)
302-
if not gotit:
303-
try:
304-
self._waiters.remove(waiter)
305-
except ValueError:
306-
pass
307303
return gotit
308304
finally:
309305
self._acquire_restore(saved_state)
306+
if not gotit:
307+
try:
308+
self._waiters.remove(waiter)
309+
except ValueError:
310+
pass
310311

311312
def wait_for(self, predicate, timeout=None):
312313
"""Wait until a condition evaluates to True.

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,4 +1518,5 @@ Cheng Zhang
15181518
Kai Zhu
15191519
Tarek Ziadé
15201520
Gennadiy Zlobin
1521+
Doug Zongker
15211522
Peter Åstrand

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ Core and Builtins
124124
Library
125125
-------
126126

127+
- Issue #22185: Fix an occasional RuntimeError in threading.Condition.wait()
128+
caused by mutation of the waiters queue without holding the lock. Patch
129+
by Doug Zongker.
130+
127131
- Issue #22287: On UNIX, _PyTime_gettimeofday() now uses
128132
clock_gettime(CLOCK_REALTIME) if available. As a side effect, Python now
129133
depends on the librt library on Solaris and on Linux (only with glibc older

0 commit comments

Comments
 (0)