问题
My programme ends unexpectedly. When I run it through pdb, it ends with:
The program exited via sys.exit(). Exit status:
but then there is no record of the stack at the instance it exited. I have no idea why it happens. Short of step and nexting through everything, is there a way to instruct pdb to enter the debugger when this is attempted, instead of honouring the sys.exit()?
回答1:
A simple-ish solution would be to monkey-patch sys.exit() before running:
$ python -m pdb my_script.py
(Pdb) def no_exit(code): raise RuntimeError('halt')
(Pdb) import sys
(Pdb) sys.exit = no_exit
(Pdb) cont
来源:https://stackoverflow.com/questions/42835017/cathing-sys-exit-in-debugger