summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-08-29 21:27:33 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-08-29 21:27:33 (GMT)
commitfa9211b11dd9b78afbb3dda617267c150ba04cf0 (patch)
treee2ae8c9370e7957ea41f72ce18a9a2a552a7a610
parent67ca33dbf44524516991d9152c4d8a7ff57f0335 (diff)
parenta64b92edd3b7c9145e014aac9a15821d7b05b71a (diff)
downloadcpython-fa9211b11dd9b78afbb3dda617267c150ba04cf0.zip
cpython-fa9211b11dd9b78afbb3dda617267c150ba04cf0.tar.gz
cpython-fa9211b11dd9b78afbb3dda617267c150ba04cf0.tar.bz2
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.
-rw-r--r--Lib/threading.py11
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS4
3 files changed, 11 insertions, 5 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index c7c4478..66620a9 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -290,6 +290,7 @@ class Condition:
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 @@ class Condition:
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.
diff --git a/Misc/ACKS b/Misc/ACKS
index a8ea6d7..200d615 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1518,4 +1518,5 @@ Cheng Zhang
Kai Zhu
Tarek Ziadé
Gennadiy Zlobin
+Doug Zongker
Peter Ã…strand
diff --git a/Misc/NEWS b/Misc/NEWS
index c9a40df..68c5d90 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -124,6 +124,10 @@ Core and Builtins
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
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