Is it possible to automatically break into the debugger when a exception is thrown?

前端 未结 6 551
栀梦
栀梦 2021-02-07 06:00

If ones catches an exception outside of the function it is originally thrown, ones loses access to the local stack. As a result one cannot inspect the values of the variables th

6条回答
  •  猫巷女王i
    2021-02-07 06:26

    For python 3 (today at 3.8), this can be done with

    python3 -m pdb myscript.py
    

    From the docs:

    When invoked as a script, pdb will automatically enter post-mortem debugging if the program being debugged exits abnormally. After post-mortem debugging (or after normal exit of the program), pdb will restart the program. Automatic restarting preserves pdb’s state (such as breakpoints) and in most cases is more useful than quitting the debugger upon program’s exit.

    Note that at launch, python will directly enter pdb mode, and you need to type c then enter to start running the script

提交回复
热议问题