def _hook(type_, value, tback):
"""Exception hook callback."""
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, tback)
else:
import traceback
import pdb
# we are NOT in interactive mode, print the exception...
traceback.print_exception(type_, value, tback)
# Dirty hack because Py27 doesn't chain exceptions
if value.args:
tb2 = value.args[-1]
if isinstance(tb2, type(tback)):
ex = value.args[-2]
print >>sys.stderr, '{}Caused by{} '.format(
ansi('1;35m'), ansi('0m')),
traceback.print_exception(type_(ex), ex, tb2)
print
# ...then start the debugger in post-mortem mode.
# pdb.pm() # deprecated
pdb.post_mortem(tback) # more "modern"
评论列表
文章目录