Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top