New submission from STINNER Victor <vstin...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue37076>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to