在gevent中,如何转储所有正在运行的greenlet的堆栈跟踪? [英] In gevent, how can I dump stack traces of all running greenlets?
本文介绍了在gevent中,如何转储所有正在运行的greenlet的堆栈跟踪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
出于调试目的,我想遍历所有greenlet并获取其跟踪记录-如何使用gevent做到这一点?
For debugging purposes, I would like to iterate over all greenlets and obtain their trace traces -- how can I do that with gevent?
基本上,我想做与 this 相同的gevent.
Basically, I would like to do the gevent equivalent of this.
推荐答案
您可以使用gc
模块遍历堆上的所有对象并搜索greenlets. Greenlets将堆栈跟踪存储为属性gr_frame
.
You can use the gc
module to iterate through all the objects on the heap and search for greenlets. Greenlets store the stack traces as an attribute gr_frame
.
import gc
import traceback
from greenlet import greenlet
for ob in gc.get_objects():
if not isinstance(ob, greenlet):
continue
if not ob:
continue
log.error(''.join(traceback.format_stack(ob.gr_frame)))
这篇关于在gevent中,如何转储所有正在运行的greenlet的堆栈跟踪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文