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:
Victor Stinner 2019-05-29 02:57:56 +02:00 committed by GitHub
parent b76302ddd0
commit 8b09500345
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 20 deletions

View file

@ -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):