-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Description
Currently when an asyncio Lock or Semaphore has been recently vacated but still has waiters queued up, the locked() method may return False, making prospective acquirers believe that if they call acquire() they will immediately proceed, without blocking.
In a threading system with pre-emptive scheduling (like Python's threading module, which uses OS threads) this makes sense, because locked() never makes any guarantee: code like
if not lock.locked():
lock.acquire()may block in the acquire() call because another thread may be executing similar code and there's a race.
But in asyncio there's no race -- there is no pre-emptive task switching and everything associated with a particular event loop runs in a single OS thread. So we could make it so that locked() checks if the queue is empty and returns True only if it is. But should we?
CC: @kumaraditya303 @cykerway @njs.
Metadata
Metadata
Assignees
Labels
Projects
Status