Python - start interactive debugger when exception would be otherwise thrown

后端 未结 4 1215
-上瘾入骨i
-上瘾入骨i 2021-02-04 03:16

Is there any way to make a python program start an interactive debugger, like what import pdb; pdb.set_trace() instead of actually throwing an exception?

I

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 04:07

    If you are inside the REPL, you can do

    import sys
    import pdb
    pdb.post_mortem(sys.last_traceback)
    

    See https://docs.python.org/2/library/pdb.html and https://docs.python.org/3/library/traceback.html

提交回复
热议问题