mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +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
|
|
@ -1002,25 +1002,15 @@ t_bootstrap(void *boot_raw)
|
|||
res = PyObject_Call(boot->func, boot->args, boot->keyw);
|
||||
if (res == NULL) {
|
||||
if (PyErr_ExceptionMatches(PyExc_SystemExit))
|
||||
/* SystemExit is ignored silently */
|
||||
PyErr_Clear();
|
||||
else {
|
||||
PyObject *file;
|
||||
PyObject *exc, *value, *tb;
|
||||
PySys_WriteStderr(
|
||||
"Unhandled exception in thread started by ");
|
||||
PyErr_Fetch(&exc, &value, &tb);
|
||||
file = _PySys_GetObjectId(&PyId_stderr);
|
||||
if (file != NULL && file != Py_None)
|
||||
PyFile_WriteObject(boot->func, file, 0);
|
||||
else
|
||||
PyObject_Print(boot->func, stderr, 0);
|
||||
PySys_WriteStderr("\n");
|
||||
PyErr_Restore(exc, value, tb);
|
||||
PyErr_PrintEx(0);
|
||||
_PyErr_WriteUnraisableMsg("in thread started by", boot->func);
|
||||
}
|
||||
}
|
||||
else
|
||||
else {
|
||||
Py_DECREF(res);
|
||||
}
|
||||
Py_DECREF(boot->func);
|
||||
Py_DECREF(boot->args);
|
||||
Py_XDECREF(boot->keyw);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue