Re: Drop into REPL when your program crashes.
Ethan Carter <[email protected]> Mon, 08 Sep 2025 21:21:20 -0300
| Newsgroups | comp.lang.python |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
Annada Behera <[email protected]> writes: > Hi, > > Recently I have been increasingly adding this piece of code as > a preamble to a lot of my code. > > import (sys, os, ipdb) > > def debug_hook(exc_type, exc_value, traceback): > if exc_type is KeyboardInterrupt: > sys.__excepthook__(exc_type, exc_value, traceback) > return > print(f"Uncaught exception: {exc_type.__name__}: {exc_value}") > ipdb.post_mortem(traceback) > > if os.environ.get('DEBUG'): sys.excepthook = debug_hook Pretty nice contribution! I had no idea such thing was possible with Python. The more Common Lispy it gets, the better it feels! :>