In a gevent application, how can I kill all greenlets that have been started?

后端 未结 2 1883
渐次进展
渐次进展 2021-02-04 08:19

I have a gevent application that spawns multiple greenlets across multiple modules. I want to be able to gracefully shutdown the application (either internally or by catching

2条回答
  •  别跟我提以往
    2021-02-04 08:54

    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)]
    )
    

提交回复
热议问题