Skip to content

Commit b5d1f0a

Browse files
committed
Added explanation comment
1 parent 195bfea commit b5d1f0a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Lib/asyncio/locks.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,24 @@ async def acquire(self):
181181
self._locked = True
182182
return True
183183

184-
_waiters = self._waiters
185184
fut = self._loop.create_future()
186-
_waiters.append(fut)
185+
self._waiters.append(fut)
186+
187+
# Finally block should be called before the CancelledError
188+
# handling as we don't want CancelledError to call
189+
# _wake_up_first() and attempt to wake up itself.
187190
try:
188191
try:
189192
await fut
190193
finally:
191-
_waiters.remove(fut)
194+
self._waiters.remove(fut)
192195
except futures.CancelledError:
193196
if not self._locked:
194197
self._wake_up_first()
195198
raise
196199

197200
self._locked = True
198201
return True
199-
200202

201203
def release(self):
202204
"""Release a lock.
@@ -221,12 +223,11 @@ def _wake_up_first(self):
221223
fut = next(iter(self._waiters))
222224
except StopIteration:
223225
return
224-
226+
225227
if not fut.done():
226228
fut.set_result(True)
227229

228230

229-
230231
class Event:
231232
"""Asynchronous equivalent to threading.Event.
232233

0 commit comments

Comments
 (0)