mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-37076: _thread.start_new_thread() calls _PyErr_WriteUnraisableMsg() (GH-13617)
_thread.start_new_thread() now logs uncaught exception raised by the function using sys.unraisablehook(), rather than sys.excepthook(), so the hook gets access to the function which raised the exception.
This commit is contained in:
parent
b76302ddd0
commit
8b09500345
4 changed files with 41 additions and 20 deletions
|
@ -154,6 +154,24 @@ class ThreadRunningTests(BasicThreadTest):
|
|||
started.acquire()
|
||||
self.assertIn("Traceback", stderr.getvalue())
|
||||
|
||||
def test_unraisable_exception(self):
|
||||
def task():
|
||||
started.release()
|
||||
raise ValueError("task failed")
|
||||
|
||||
started = thread.allocate_lock()
|
||||
with support.catch_unraisable_exception() as cm:
|
||||
with support.wait_threads_exit():
|
||||
started.acquire()
|
||||
thread.start_new_thread(task, ())
|
||||
started.acquire()
|
||||
|
||||
self.assertEqual(str(cm.unraisable.exc_value), "task failed")
|
||||
self.assertIs(cm.unraisable.object, task)
|
||||
self.assertEqual(cm.unraisable.err_msg,
|
||||
"Exception ignored in thread started by")
|
||||
self.assertIsNotNone(cm.unraisable.exc_traceback)
|
||||
|
||||
|
||||
class Barrier:
|
||||
def __init__(self, num_threads):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue