[New-bugs-announce] [issue37076] _thread.start_new_thread(): call sys.unraisablehook() to handle uncaught exceptions

STINNER Victor report at bugs.python.org
Tue May 28 06:15:10 EDT 2019


New submission from STINNER Victor <vstinner at redhat.com>:

Python 3.8 now has 3 hooks for uncaught exceptions:

* sys.excepthook()
* sys.unraisablehook()
* threading.excepthook()

_thread.start_new_thread() calls none of these hooks, but directly logs the exception.

I propose to modify it to reuse sys.unraisablehook(): see attached PR.

--

Using threading.excepthook() would be another option, but _thread.start_new_thread() is usually wrapped in threading.Thread.run() which already uses threading.excepthook(). It might be surprising to see two bugs from the same thread using threading.excepthook().

Moreover, right now, _thread is the "low-level" API to access threads: it doesn't acces threading. I'm not comfortable by adding an inter-dependency between _thread (low-level) and threading (high-level).

If threading.Thread.run() is correctly written, it should not raise an exception. In the worst case, threading.excepthook should handle the exception. _thread.start_new_thread() should never get an exception raised by threading if threading.excepthook does correctly its job.

----------
components: Library (Lib)
messages: 343756
nosy: vstinner
priority: normal
severity: normal
status: open
title: _thread.start_new_thread(): call sys.unraisablehook() to handle uncaught exceptions
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37076>
_______________________________________


More information about the New-bugs-announce mailing list