Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit87a865e

Browse files
bpo-34767: Do not always create a collections.deque() in asyncio.Lock() (GH-13834)
https://bugs.python.org/issue34767(cherry picked from commit9aa7856)Co-authored-by: Zackery Spytz <zspytz@gmail.com>
1 parentf2054d9 commit87a865e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

‎Lib/asyncio/locks.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff 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
ifloopisnotNone:
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-
ifnotself._lockedandall(w.cancelled()forwinself._waiters):
185+
if (notself._lockedand (self._waitersisNoneor
186+
all(w.cancelled()forwinself._waiters))):
186187
self._locked=True
187188
returnTrue
188189

190+
ifself._waitersisNone:
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+
ifnotself._waiters:
231+
return
227232
try:
228233
fut=next(iter(self._waiters))
229234
exceptStopIteration:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Do not always create a:class:`collections.deque` in:class:`asyncio.Lock`.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp