Start pdb on exception in Tornado's ioloop

烂漫一生 提交于 2019-12-11 13:22:23

问题


It's often useful to do this in standalone Python programs:

def excepthook(typ, value, tb):
    traceback.print_exception(typ, value, tb)
    pdb.pm()

...
if log.getEffectiveLevel() == logging.DEBUG:
    sys.excepthook = excepthook

(i.e. if uncatched exception happens, program is dropped into pdb post-mortem mode)

But that doesn't work with Tornado ioloop bc it seems that ioloop catches uncatched exceptions and prints or logs them. If I install above hook, the program enters post-mortem mode only on pressing Ctrl-C which is kind of late. :-)

Is there a way of making this happen without monkey-patching Tornado?


回答1:


You could subclass tornado's IOLoop and override handle_callback_exception. See http://www.tornadoweb.org/en/stable/ioloop.html#tornado.ioloop.IOLoop.handle_callback_exception

I guess this isn't much different from monkey-patching, though...



来源:https://stackoverflow.com/questions/20660657/start-pdb-on-exception-in-tornados-ioloop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!