在龙卷风的ioloop中异常启动pdb [英] Start pdb on exception in Tornado's ioloop

查看:89
本文介绍了在龙卷风的ioloop中异常启动pdb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在独立的Python程序中执行此操作通常很有用:

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

(即,如果发生未捕获的异常,程序将进入pdb验尸模式)

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

但这不适用于Tornado ioloop bc,看来ioloop会捕获未捕获的异常并打印或记录它们.如果我将其安装在钩子上方,则仅在按Ctrl-C时程序才会进入验尸模式,这有点晚了. :-)

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?

推荐答案

您可以将龙卷风的IOLoop子类化,并覆盖handle_callback_exception.请参见 http://www.tornadoweb.org/en/stable/ioloop.html#tornado.ioloop.IOLoop.handle_callback_exception

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...

这篇关于在龙卷风的ioloop中异常启动pdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆