Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created November 11, 2020 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save podhmo/5964702e7471ccaba969105468291efa to your computer and use it in GitHub Desktop.
Save podhmo/5964702e7471ccaba969105468291efa to your computer and use it in GitHub Desktop.
import sys
def foo():
print("foo")
bar()
print("foo")
def bar():
print("bar")
boo()
print("bar")
def boo():
print("boo")
raise Exception("oops")
# https://www.oreilly.com/library/view/python-cookbook/0596001673/ch14s06.html
def info(type, value, tb):
if hasattr(sys, "ps1") or not sys.stderr.isatty():
# You are in interactive mode or don't have a tty-like
# device, so call the default hook
sys.__excepthook__(type, value, tb)
else:
import traceback, pdb
# You are NOT in interactive mode; print the exception...
traceback.print_exception(type, value, tb)
# ...then start the debugger in post-mortem mode
pdb.pm()
sys.excepthook = info
foo()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment