[Python-checkins] python/dist/src/Modules threadmodule.c,2.53,2.54

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Tue, 29 Apr 2003 12:44:12 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv31310

Modified Files:
	threadmodule.c 
Log Message:
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()).


Index: threadmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/threadmodule.c,v
retrieving revision 2.53
retrieving revision 2.54
diff -C2 -d -r2.53 -r2.54
*** threadmodule.c	5 Sep 2002 21:31:04 -0000	2.53
--- threadmodule.c	29 Apr 2003 19:44:05 -0000	2.54
***************
*** 180,192 ****
  	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");
  			PyErr_PrintEx(0);
  		}
--- 180,196 ----
  	res = PyEval_CallObjectWithKeywords(
  		boot->func, boot->args, boot->keyw);
  	if (res == NULL) {
  		if (PyErr_ExceptionMatches(PyExc_SystemExit))
  			PyErr_Clear();
  		else {
! 			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);
  		}
***************
*** 194,197 ****
--- 198,205 ----
  	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();