Start pdb on exception in Tornado's ioloop

699 views Asked by At

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

There are 1 answers

0
dano On BEST ANSWER

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