Created
October 11, 2019 17:53
-
-
Save yaroslavvb/5de8ad332f2e37aa542e69e208476433 to your computer and use it in GitHub Desktop.
install_pdb_handler
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
def install_pdb_handler(): | |
"""Signals to automatically start pdb: | |
1. CTRL+\\ breaks into pdb. | |
2. pdb gets launched on exception. | |
""" | |
import signal | |
import pdb | |
def handler(_signum, _frame): | |
pdb.set_trace() | |
signal.signal(signal.SIGQUIT, handler) | |
# Drop into PDB on exception | |
# from https://stackoverflow.com/questions/13174412 | |
def info(type_, value, tb): | |
if hasattr(sys, 'ps1') or not sys.stderr.isatty(): | |
# we are in interactive mode or we don't have a tty-like | |
# device, so we call the default hook | |
sys.__excepthook__(type_, value, tb) | |
else: | |
import traceback | |
import pdb | |
# we are NOT in interactive mode, print the exception... | |
traceback.print_exception(type_, value, tb) | |
print() | |
# ...then start the debugger in post-mortem mode. | |
pdb.pm() | |
sys.excepthook = info | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment