Queue types
asyncio provides a couple of variant Queue types that return their stored values in different orders.
Instances of PriorityQueue give back the smallest object they contain according to a less than comparison when we call get or get_nowait. So, if our priority queue contains 34, 2, 5, and 97, calling its get coroutine would return 2. The next time, it would return 5, then 34, and then 97.
A LifoQueue method, on the other hand, always gives back the most recently added object. It is, in other words, a stack data structure. asyncio also provides a joinable Queue class, which adds an extra join coroutine and a method called task_done. With a little bit of extra work, using a joinable queue allows coroutines to pause and wait until ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access