File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -158,7 +158,7 @@ class Lock(_ContextManagerMixin):
158158 """
159159
160160 def __init__ (self , * , loop = None ):
161- self ._waiters = collections . deque ()
161+ self ._waiters = None
162162 self ._locked = False
163163 if loop is not None :
164164 self ._loop = loop
@@ -182,10 +182,13 @@ async def acquire(self):
182182 This method blocks until the lock is unlocked, then sets it to
183183 locked and returns True.
184184 """
185- if not self ._locked and all (w .cancelled () for w in self ._waiters ):
185+ if (not self ._locked and (self ._waiters is None or
186+ all (w .cancelled () for w in self ._waiters ))):
186187 self ._locked = True
187188 return True
188189
190+ if self ._waiters is None :
191+ self ._waiters = collections .deque ()
189192 fut = self ._loop .create_future ()
190193 self ._waiters .append (fut )
191194
@@ -224,6 +227,8 @@ def release(self):
224227
225228 def _wake_up_first (self ):
226229 """Wake up the first waiter if it isn't done."""
230+ if not self ._waiters :
231+ return
227232 try :
228233 fut = next (iter (self ._waiters ))
229234 except StopIteration :
Original file line number Diff line number Diff line change 1+ Do not always create a :class: `collections.deque ` in :class: `asyncio.Lock `.
You can’t perform that action at this time.
0 commit comments