diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-29 00:57:56 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-29 00:57:56 (GMT) |
commit | 8b09500345d998f3ff1e363a5210bc87f42ff306 (patch) | |
tree | 3f03ee8d5f60fece00d48ae305253328413ae9d0 /Lib | |
parent | b76302ddd0896cb39ce69909349b53db6e7776e2 (diff) | |
download | cpython-8b09500345d998f3ff1e363a5210bc87f42ff306.zip cpython-8b09500345d998f3ff1e363a5210bc87f42ff306.tar.gz cpython-8b09500345d998f3ff1e363a5210bc87f42ff306.tar.bz2 |
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.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_thread.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_thread.py b/Lib/test/test_thread.py index f4eb830..f946f7b 100644 --- a/Lib/test/test_thread.py +++ b/Lib/test/test_thread.py @@ -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): |