summaryrefslogtreecommitdiffstats
path: root/Modules/threadmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-04-29 19:44:05 (GMT)
committerGuido van Rossum <guido@python.org>2003-04-29 19:44:05 (GMT)
commit24ccca156557a64ca0574a2ad384506d246d030b (patch)
treeb712caf76e1af5302601dcd9e20368e17228ae24 /Modules/threadmodule.c
parentc689918c941d366716c9a630414fb6703581b425 (diff)
downloadcpython-24ccca156557a64ca0574a2ad384506d246d030b.zip
cpython-24ccca156557a64ca0574a2ad384506d246d030b.tar.gz
cpython-24ccca156557a64ca0574a2ad384506d246d030b.tar.bz2
When an unhandled exception happens, report the repr() of the function
that was used to start the thread. This is useful to track down the source of the problem when there is no traceback, as can happen when a daemon thread gets to run after Python is finialized (a new kind of event, somehow this is now possible due to changes in Py_Finalize()).
Diffstat (limited to 'Modules/threadmodule.c')
-rw-r--r--Modules/threadmodule.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index 62fd76a..8b174b3 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -179,20 +179,28 @@ t_bootstrap(void *boot_raw)
PyEval_AcquireThread(tstate);
res = PyEval_CallObjectWithKeywords(
boot->func, boot->args, boot->keyw);
- Py_DECREF(boot->func);
- Py_DECREF(boot->args);
- Py_XDECREF(boot->keyw);
- PyMem_DEL(boot_raw);
if (res == NULL) {
if (PyErr_ExceptionMatches(PyExc_SystemExit))
PyErr_Clear();
else {
- PySys_WriteStderr("Unhandled exception in thread:\n");
+ PyObject *file;
+ PySys_WriteStderr(
+ "Unhandled exception in thread started by ");
+ file = PySys_GetObject("stderr");
+ if (file)
+ PyFile_WriteObject(boot->func, file, 0);
+ else
+ PyObject_Print(boot->func, stderr, 0);
+ PySys_WriteStderr("\n");
PyErr_PrintEx(0);
}
}
else
Py_DECREF(res);
+ Py_DECREF(boot->func);
+ Py_DECREF(boot->args);
+ Py_XDECREF(boot->keyw);
+ PyMem_DEL(boot_raw);
PyThreadState_Clear(tstate);
PyThreadState_DeleteCurrent();
PyThread_exit_thread();