From a64b92edd3b7c9145e014aac9a15821d7b05b71a Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Fri, 29 Aug 2014 23:26:36 +0200 Subject: 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. --- Lib/threading.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Lib/threading.py') diff --git a/Lib/threading.py b/Lib/threading.py index 34070830e7..dfe9d41b9f 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -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. -- cgit v1.2.1