]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #17385: Fix quadratic behavior in threading.Condition
authorRaymond Hettinger <python@rcn.com>
Mon, 11 Mar 2013 00:57:28 +0000 (17:57 -0700)
committerRaymond Hettinger <python@rcn.com>
Mon, 11 Mar 2013 00:57:28 +0000 (17:57 -0700)
Lib/threading.py
Misc/NEWS

index 35d2e8a552b2a6adc36dabc110dcbd4c57fa3ef0..0261ee2706fc11b14dca2d118e6be7f560af5e02 100644 (file)
@@ -10,6 +10,12 @@ except ImportError:
     from time import time as _time
 from traceback import format_exc as _format_exc
 from _weakrefset import WeakSet
+try:
+    from _itertools import islice as _slice
+    from _collections import deque as _deque
+except ImportError:
+    from itertools import islice as _islice
+    from collections import deque as _deque
 
 # Note regarding PEP 8 compliant names
 #  This threading model was originally inspired by Java, and inherited
@@ -146,7 +152,7 @@ class Condition:
             self._is_owned = lock._is_owned
         except AttributeError:
             pass
-        self._waiters = []
+        self._waiters = _deque()
 
     def __enter__(self):
         return self._lock.__enter__()
@@ -217,7 +223,7 @@ class Condition:
         if not self._is_owned():
             raise RuntimeError("cannot notify on un-acquired lock")
         __waiters = self._waiters
-        waiters = __waiters[:n]
+        waiters = _deque(_islice(__waiters, n))
         if not waiters:
             return
         for waiter in waiters:
index fd52b1c825cdcd8122e210784d7317589f594484..4ed92674ff86f6ffec2eea23a6e6c6f7f038e5c0 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -277,6 +277,9 @@ Core and Builtins
 Library
 -------
 
+_ Issue #17385: Fix quadratic behavior in threading.Condition.  The FIFO
+  queue now uses a deque instead of a list.
+
 - Issue #14645: The email generator classes now produce output using the
   specified linesep throughout.  Previously if the prolog, epilog, or
   body were stored with a different linesep, that linesep was used.  This