In a gevent application, how can I kill all greenlets that have been started?
This didn't quite work for the versions of gevent (1.2.2) and greenlet (0.4.13) I was using but the following does:
import gc
import gevent
gevent.killall(
[obj for obj in gc.get_objects() if isinstance(obj, gevent.Greenlet)]
)
According to another SO answer, it's possible "to iterate through all the objects on the heap and search for greenlets." So, I imagine this ought to work:
import gc
import gevent
from greenlet import greenlet
gevent.killall([obj for obj in gc.get_objects() if isinstance(obj, greenlet)])