If you like this, you might also like my small debugging utility, a better_exchook replacement: https://github.com/albertz/py_better_exchook Simple example: assert x == 4 When this fails, it will print the value of `x`.
sys.excepthook = better_exchook
instead of something like: def generate_better_exchook(..., current_excepthook=None):
previous_excepthook = current_excepthook
def better_exchook(exception_type, exception_instance, exception_traceback):
...
if previous_excepthook is not None:
previous_excepthook(exception_type, exception_instance, exception_traceback)
return better_exchook
and then sys.excepthook = generate_better_excepthook(..., sys.excepthook)
Do you prefer not to do this because it would keep this closure around in memory until the Python process exits?