Drops python to a debugger on unhandled exceptions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Import this module to make python drop to the debugger | |
when an undhandled exception is raised. | |
Original script from: | |
http://code.activestate.com/recipes/65287/ | |
""" | |
import sys | |
__old_excepthook__ = sys.excepthook | |
def info(type, value, tb): | |
if hasattr(sys, 'ps1') or \ | |
not sys.stderr.isatty() or \ | |
not sys.stdin.isatty() or \ | |
not sys.stdout.isatty() or \ | |
type == SyntaxError: | |
# we are in interactive mode or we don't have a tty-like | |
# device, so we call the default hook | |
__old_excepthook__(type, value, tb) | |
else: | |
# dump the exception and then start the debugger in | |
# post-mortem mode. | |
import traceback, pdb | |
traceback.print_exception(type, value, tb) | |
pdb.pm() | |
sys.excepthook = info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment