summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-10-30 21:48:26 +0000
committerChristian Heimes <christian@cheimes.de>2008-10-30 21:48:26 +0000
commit84213ad540d677ce759458f2b536e1acfbef601a (patch)
tree26d21664cfcbdb13ecf302ac89fa916d6ae02bc0 /Python
parent6c83e3da5f20ef73db1306e6ae3ac0acdf557f52 (diff)
downloadcpython-84213ad540d677ce759458f2b536e1acfbef601a.tar.gz
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.
Diffstat (limited to 'Python')
-rw-r--r--Python/bltinmodule.c2
-rw-r--r--Python/codecs.c1
-rw-r--r--Python/pystate.c1
-rw-r--r--Python/pythonrun.c16
-rw-r--r--Python/sysmodule.c2
5 files changed, 20 insertions, 2 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 8159fe84d5..d7f5084a58 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2282,7 +2282,7 @@ static struct PyModuleDef builtinsmodule = {
PyModuleDef_HEAD_INIT,
"builtins",
builtin_doc,
- 0,
+ -1, /* multiple "initialization" just copies the module dict. */
builtin_methods,
NULL,
NULL,
diff --git a/Python/codecs.c b/Python/codecs.c
index 66576c481c..ebddc09d7b 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -869,5 +869,6 @@ static int _PyCodecRegistry_Init(void)
return -1;
}
Py_DECREF(mod);
+ interp->codecs_initialized = 1;
return 0;
}
diff --git a/Python/pystate.c b/Python/pystate.c
index 9479256718..2a9b7443f9 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -76,6 +76,7 @@ PyInterpreterState_New(void)
interp->codec_search_path = NULL;
interp->codec_search_cache = NULL;
interp->codec_error_registry = NULL;
+ interp->codecs_initialized = 0;
#ifdef HAVE_DLOPEN
#ifdef RTLD_NOW
interp->dlopenflags = RTLD_NOW;
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 4fb2b3e40d..61cdf6d745 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -562,8 +562,13 @@ Py_NewInterpreter(void)
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 @@ Py_NewInterpreter(void)
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();
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 952f7e5904..af960bc070 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1231,7 +1231,7 @@ static struct PyModuleDef sysmodule = {
PyModuleDef_HEAD_INIT,
"sys",
sys_doc,
- 0,
+ -1, /* multiple "initialization" just copies the module dict. */
sys_methods,
NULL,
NULL,