diff --git a/Lib/threading.py b/Lib/threading.py --- a/Lib/threading.py +++ b/Lib/threading.py @@ -2,6 +2,8 @@ import sys as _sys import _thread +from _collections import deque as _deque +from itertools import islice as _islice from time import sleep as _sleep try: @@ -146,7 +148,7 @@ self._is_owned = lock._is_owned except AttributeError: pass - self._waiters = [] + self._waiters = _deque() def __enter__(self): return self._lock.__enter__() @@ -217,7 +219,7 @@ if not self._is_owned(): raise RuntimeError("cannot notify on un-acquired lock") __waiters = self._waiters - waiters = __waiters[:n] + waiters = list(_islice(__waiters, n)) if not waiters: return for waiter in waiters: