Created
September 10, 2018 10:38
-
-
Save dcragusa/9c00c5e55d116961c5aa8bd51865fcd9 to your computer and use it in GitHub Desktop.
Convenience module that when imported automatically drops you into pdb when an exception is hit
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
# From https://stackoverflow.com/a/242531/2864129 | |
# Put in pythonpath and 'import debug' | |
import sys | |
def info(type_, value, tb): | |
if hasattr(sys, 'ps1') or not sys.stderr.isatty() or type_ is KeyboardInterrupt: | |
# we are in interactive mode / we don't have a tty-like device / user-triggered, so we call the default hook | |
sys.__excepthook__(type_, value, tb) | |
else: | |
import traceback, pdb | |
# we are NOT in interactive mode, print the exception... | |
traceback.print_exception(type_, value, tb) | |
pdb.post_mortem(tb) | |
sys.excepthook = info |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment