Posts

Showing posts with the label python-asyncio

Does the lock in asyncio.Condition have other purpose besides compatibility with threading.Condition?

Image
Clash Royale CLAN TAG #URR8PPP Does the lock in asyncio.Condition have other purpose besides compatibility with threading.Condition? I'd like to ask about asyncio.Condition. I'm not familiar with the concept, but I know and understand locks, semaphores, and queues since my student years. I could not find a good explanation or typical use cases, just this example. I looked at the source. The core fnctionality is achieved with a FIFO of futures. Each waiting coroutine adds a new future and awaits it. Another coroutine may call notify() which sets the result of one or optionally more futures from the FIFO and that wakes up the same number of waiting coroutines. Really simple up to this point. notify() However, the implementation and the usage is more complicated than this. A waiting coroutine must first acquire a lock associated with the condition in order to be able to wait (and the wait() releases it while waiting). Also the notifier must acquire a lock to be able to notify()....