]> granicus.if.org Git - python/commitdiff
Issue #22185: Fix an occasional RuntimeError in threading.Condition.wait() caused...
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 29 Aug 2014 21:26:36 +0000 (23:26 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 29 Aug 2014 21:26:36 +0000 (23:26 +0200)
Patch by Doug Zongker.

Lib/threading.py
Misc/ACKS
Misc/NEWS

index 34070830e78c82a29eacfe1ffc5b2c8f50b2db82..dfe9d41b9ff86e5973062e699b14f5871511b31b 100644 (file)
@@ -284,6 +284,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()
@@ -293,14 +294,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.
index 4986dc619d5f230275360bcc9ab20d9c97762c5f..5a388ffa12f905f80e18644cad9830778ba86353 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1500,4 +1500,5 @@ Cheng Zhang
 Kai Zhu
 Tarek Ziadé
 Gennadiy Zlobin
+Doug Zongker
 Peter Ã…strand
index 854fc737ea1f1c6bea9e9e85c1d42a019973cf81..ab5eee6bb903a617d9635370dae35428fd8b85d3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,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 #22182: Use e.args to unpack exceptions correctly in
   distutils.file_util.move_file. Patch by Claudiu Popa.