diff Python/pythonrun.c @ 43718:e510b716bd80

Patch 1352 (continued in issue 1329) by Christian Heimes. Before sys.stderr is set to the proper thing, set it to a really simple file-like object that can print tracebacks using direct file descriptor I/O. This is handy for debugging.
author Guido van Rossum <guido@python.org>
date Tue, 30 Oct 2007 18:34:07 +0000
parents 00b136b7da84
children 0d462d789b18
line wrap: on
line diff
--- a/Python/pythonrun.c	Tue Oct 30 18:13:17 2007 +0000
+++ b/Python/pythonrun.c	Tue Oct 30 18:34:07 2007 +0000
@@ -151,7 +151,7 @@
 {
 	PyInterpreterState *interp;
 	PyThreadState *tstate;
-	PyObject *bimod, *sysmod;
+	PyObject *bimod, *sysmod, *pstderr;
 	char *p;
 #if defined(HAVE_LANGINFO_H) && defined(CODESET)
 	char *codeset;
@@ -228,6 +228,13 @@
 	PyDict_SetItemString(interp->sysdict, "modules",
 			     interp->modules);
 
+	/* Set up a preliminary stderr printer until we have enough
+	   infrastructure for the io module in place. */
+	pstderr = PyFile_NewStdPrinter(fileno(stderr));
+	if (pstderr == NULL)
+		Py_FatalError("Py_Initialize: can't set preliminary stderr");
+	PySys_SetObject("stderr", pstderr);
+
 	_PyImport_Init();
 
 	/* initialize builtin exceptions */