[Python-checkins] cpython (merge 3.4 -> default): Issue #22185: Fix an occasional RuntimeError in threading.Condition.wait()

antoine.pitrou python-checkins at python.org
Fri Aug 29 23:27:44 CEST 2014


http://hg.python.org/cpython/rev/78a38f8bd5d9
changeset:   92269:78a38f8bd5d9
parent:      92267:ab81b4cdc33c
parent:      92268:4cce39cfe46c
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Fri Aug 29 23:27:33 2014 +0200
summary:
  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.

files:
  Lib/threading.py |  11 ++++++-----
  Misc/ACKS        |   1 +
  Misc/NEWS        |   4 ++++
  3 files changed, 11 insertions(+), 5 deletions(-)


diff --git a/Lib/threading.py b/Lib/threading.py
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -290,6 +290,7 @@
         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 @@
                     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
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1518,4 +1518,5 @@
 Kai Zhu
 Tarek Ziadé
 Gennadiy Zlobin
+Doug Zongker
 Peter Åstrand
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -124,6 +124,10 @@
 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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list