Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In gevent, how can I dump stack traces of all running greenlets?

Tags:

python

gevent

For debugging purposes, I would like to iterate over all greenlets and obtain their trace traces -- how can I do that with gevent?

Basically, I would like to do the gevent equivalent of this.

like image 675
kdt Avatar asked Sep 20 '12 10:09

kdt


1 Answers

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)))
like image 72
Stephen Diehl Avatar answered Oct 05 '22 16:10

Stephen Diehl