diff Python/pythonrun.c @ 49613:efef5fc45a9a

Issue 3723: Fixed initialization of subinterpreters The patch fixes several issues with Py_NewInterpreter as well as the demo for multiple subinterpreters. Most of the patch was written by MvL with help from Benjamin, Amaury and me. Graham Dumpleton has verified that this patch fixes an issue with mod_wsgi.
author Christian Heimes <christian@cheimes.de>
date Thu, 30 Oct 2008 21:48:26 +0000
parents 9fc573fbaf5e
children f3234e43e1fe
line wrap: on
line diff
--- a/Python/pythonrun.c	Thu Oct 30 21:40:04 2008 +0000
+++ b/Python/pythonrun.c	Thu Oct 30 21:48:26 2008 +0000
@@ -562,8 +562,13 @@
 			goto handle_error;
 		Py_INCREF(interp->builtins);
 	}
+
+	/* initialize builtin exceptions */
+	_PyExc_Init();
+
 	sysmod = _PyImport_FindExtension("sys", "sys");
 	if (bimod != NULL && sysmod != NULL) {
+		PyObject *pstderr;
 		interp->sysdict = PyModule_GetDict(sysmod);
 		if (interp->sysdict == NULL)
 			goto handle_error;
@@ -571,7 +576,18 @@
 		PySys_SetPath(Py_GetPath());
 		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);
+		PySys_SetObject("__stderr__", pstderr);
+
 		_PyImportHooks_Init();
+                if (initstdio() < 0)
+                    Py_FatalError(
+                        "Py_Initialize: can't initialize sys standard streams");
 		initmain();
 		if (!Py_NoSiteFlag)
 			initsite();