The asyncio Queue class

The asyncio's Queue has both put and get methods as coroutines. So, we need to call them with await and we have to already be in a coroutine to call them, unless we were to actually use the ensure_future function to launch them as separate tasks as shown in the following code example of the Queue class:

However, the Queue class also has methods called put_nowait and get_nowait, which are not coroutines, and can be called from anywhere. This makes the Queue class quite useful for communicating new data to a system of coroutines as well as sending data between coroutine tasks.

Get Daniel Arbuckle’s Mastering Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.