greenlet
greenlet is a Python package that provides lightweight in-process concurrent programming through micro-threads called 'greenlets'. The current version is 3.3.2, released on February 20, 2026. The library has a stable release cadence, with updates addressing compatibility and performance improvements.
Warnings
- breaking Support for Python 3.9 was dropped in version 3.3.0.
- breaking Support for Python 3.7 and 3.8 was removed in version 3.2.0.
- gotcha Mixing greenlets and signal handlers can lead to hangs if the signal handler switches greenlets without returning.
- gotcha Using non-reentrant native functions within greenlets can cause subtle issues.
- gotcha Greenlets cannot switch between different Python threads.
- gotcha Garbage collection of greenlets can lead to 'GreenletExit' exceptions if not handled properly.
Install
-
pip install greenlet
Imports
- greenlet
from greenlet import greenlet
- getcurrent
from greenlet import getcurrent
Quickstart
from greenlet import greenlet
def test1():
print("[gr1] main -> test1")
gr2.switch()
print("[gr1] test1 <- test2")
return 'test1 done'
def test2():
print("[gr2] test1 -> test2")
gr1.switch()
gr1 = greenlet(test1)
gr2 = greenlet(test2)
gr1.switch()