Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/asyncio/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ def __repr__(self):
return f'<{res[1:-1]} [{extra}]>'

def locked(self):
"""Return True if lock is acquired."""
return self._locked
"""Return True if lock is acquired or if there are active waiters."""
return self._locked or self._waiters

async def acquire(self):
"""Acquire a lock.
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_asyncio/test_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async def lockit(name, blocker):
tb.cancel()
self.assertTrue(lock._waiters[0].cancelled())
await asyncio.sleep(0)
self.assertFalse(lock.locked())
self.assertTrue(lock.locked())
self.assertTrue(ta.done())
self.assertTrue(tb.cancelled())
await tc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:meth:`asyncio.Lock.locked` now returns ``True`` when it has active waiters. Contributed by Emerson Beckwith.
Loading