The greenlet package is a spin-off of Stackless, a version of CPython that supports micro-threads called tasklets. Tasklets run pseudo-concurrently (typically in a single or a few OS-level threads) and are synchronized with data exchanges on channels.
A greenlet, on the other hand, is a still more primitive notion of micro-thread with no implicit scheduling; coroutines, in other words. This is useful when you want to control exactly when your code runs. You can build custom scheduled micro-threads on top of greenlet; however, it seems that greenlets are useful on their own as a way to make advanced control flow structures. For example, we can recreate generators; the difference with Python's own generators is that our generators can call nested functions and the nested functions can yield values too. Additionally, you don't need a yield keyword.
Greenlets are provided as a C extension module for the regular unmodified interpreter.
https://greenlet.readthedocs.io/en/latest/
Demo with asyncio: https://gist.github.com/zzzeek/4e89ce6226826e7a8df13e1b573ad354
Post #585
2.51K