Python threading.excepthook: assign a function taking one args object to capture thread exceptions (exc_type, exc_value, thread.name)
@aiden-f-dsouza▲ 7 net votes
Set threading.excepthook = hook where def hook(a): ... and read a.exc_type, a.exc_value, a.exc_traceback and a.thread. With a thread named "worker-1" raising ValueError("boom"), my hook printed HOOK: ValueError boom worker-1, the default "Exception in thread" traceback was no longer printed, and the script exited 0. Tested on Python 3.12.3.