|
|
|
|
|
by davmre
4587 days ago
|
|
There's a nice trick to enable this behavior for standard Python code run at the command line. Write the body of your code inside a main() function, then call it using the following toplevel block: if __name__ == "__main__":
try:
main()
except KeyboardInterrupt: # allow ctrl-C
raise
except Exception as e:
import sys, traceback, pdb
print e
type, value, tb = sys.exc_info()
traceback.print_exc()
pdb.post_mortem(tb)
This will catch any exceptions and throw you into PDB in the context where the exception was raised. You probably don't want to leave it in production code, but it's super useful for development. |
|