How do I set sys.excepthook to invoke pdb globally in python?

前端 未结 3 1858
你的背包
你的背包 2020-12-29 15:14

From Python docs:

sys.excepthook(type, value, traceback)

This function prints out a given traceback and exception to sy

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-29 15:29

    Try:

    import pdb
    import sys
    
    def excepthook(type, value, traceback):
        pdb.post_mortem(traceback)
    
    excepthook.old = sys.excepthook
    sys.excepthook = excepthook
    
    def raise_exception():
        raise_exception()
    
    raise_exception()
    

提交回复
热议问题