prevent writing to stderr from messing up the exception state (closes #14474)
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index 4e41085..73ee382 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -618,6 +618,8 @@
PyErr_Clear();
else {
PyObject *file;
+ PyObject *exc, *value, *tb;
+ PyErr_Fetch(&exc, &value, &tb);
PySys_WriteStderr(
"Unhandled exception in thread started by ");
file = PySys_GetObject("stderr");
@@ -625,6 +627,7 @@
PyFile_WriteObject(boot->func, file, 0);
else
PyObject_Print(boot->func, stderr, 0);
+ PyErr_Restore(exc, value, tb);
PySys_WriteStderr("\n");
PyErr_PrintEx(0);
}