Here we need to modify Python's processing flow after the exception occurs Sys.excepthook is the exception handler for the Python system, overrides a custom processor, and starts the PDB after printing the exception information.
ImportSYSdefinfo (type, value, TB):#Exception Type #Exception Value #Call Stack ifHasattr (SYS,'PS1')or notSys.stderr.isatty ():#we're in interactive mode or we don't have a tty-like #device, so we call the default hookSys.__excepthook__(type, value, TB)Else: ImportTraceback, PDB#We is not in interactive mode, print the exception ...traceback.print_exception (type, value, TB)Print #... then start the debugger in Post-mortem mode.Pdb.post_mortem (TB) Sys.excepthook= info
As long as in the code, start import this custom debug module, you can modify the system default exception handling process __excepthook__
----------------------------
Follow the public number:
Digging gold miners: goldminer1024
Put your wings on the ideal for your quantitative investment
After
Python exception, start debug Debug