Generator Based Coroutines

This lesson goes into the details of generator-based coroutines in Python.

We'll cover the following...

Generator Based Coroutines

Some of the readers might want to skip this lesson and head straight to native coroutines section but following through the discussion on legacy generator based coroutines can be useful when working with older code-bases.

Coroutines formally became part of Python in version 2.4 when generators were enhanced via PEP-342. And in Python 3.4, asyncio framework introduced an event loop which enabled asynchronous programs in Python. Note that with PEP-342, all generators received the new methods. So all generators fit the textbook definition of a coroutine. In fact, a post PEP-342 Python generator is functionally equivalent of what the world outside Python would call a coroutine. However, Python created a distinction between Python generators and ...