This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vlasovskikh
Recipients CyberJacob, Decorater, Matt Groth, ellisj, eric.araujo, mwh, ncoghlan, pitrou, tiagoaoa, tim.peters, undercoveridiot, vlasovskikh, vstinner
Date 2018-08-04.15:46:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> Would it be possible to modify the default implementation of sys.excepthook to have a different output when it's not called from the main thread? Mimick the current traceback from threads.

I agree it's a good idea to mimic what `_thread` does in case of both handled and unhandled exceptions. Why would you want to do it in `sys.excepthook`? The code for handling unhandled exceptions in `_thread` threads is located in `_threadmodule.c` itself, so there is no dependency from `sys` to `_thread`. By following the same logic, the code for handling unhandled exceptions in `threading` should be located in ``, like it does now. So the only thing that's missing in the pull request compared to `_thread` is the output:

   Unhandled exception in thread started by <function <lambda> at 0x7f6769ca8e18>

for all the exceptions: not caught by the sys.excepthook **and** caught by the sys.exceptook.

> An alternative would be to introduce a new hook to log exceptions in threads, ex: sys.threadexcepthook. That hoook would take a 4th parameter. But Andrey Vlasovskikh didn't like this idea.

I'm overall OK with this idea, but I would prefer to make the existing `sys.excepthook` API applicable to all the exceptions: for the main thread (works well), for `_thread` threads (works well) and for `threading` threads (doesn't work).
Date User Action Args
2018-08-04 15:46:54vlasovskikhsetrecipients: + vlasovskikh, mwh, tim.peters, ncoghlan, ellisj, pitrou, vstinner, tiagoaoa, eric.araujo, undercoveridiot, Decorater, CyberJacob, Matt Groth
2018-08-04 15:46:54vlasovskikhsetmessageid: <>
2018-08-04 15:46:54vlasovskikhlinkissue1230540 messages
2018-08-04 15:46:53vlasovskikhcreate