Skip to content

Commit 3f2b2bb

Browse files
author
Emerson Beckwith
committed
Fixed asyncio lock.locked returning False when waiters exist
1 parent 5b85756 commit 3f2b2bb

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

Lib/asyncio/locks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def __repr__(self):
8484
return f'<{res[1:-1]} [{extra}]>'
8585

8686
def locked(self):
87-
"""Return True if lock is acquired."""
88-
return self._locked
87+
"""Return True if lock is acquired or if there are active waiters."""
88+
return self._locked or self._waiters
8989

9090
async def acquire(self):
9191
"""Acquire a lock.

Lib/test/test_asyncio/test_locks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,11 @@ async def lockit(name, blocker):
186186
tb.cancel()
187187
self.assertTrue(lock._waiters[0].cancelled())
188188
await asyncio.sleep(0)
189-
self.assertFalse(lock.locked())
189+
self.assertTrue(lock.locked())
190190
self.assertTrue(ta.done())
191191
self.assertTrue(tb.cancelled())
192192
await tc
193+
self.assertTrue(tc.done())
193194

194195
async def test_cancel_release_race(self):
195196
# Issue 32734

0 commit comments

Comments
 (0)