debug.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:sysl 作者: anz-bank 项目源码 文件源码
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"
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号