[Python-Dev] Re: [PyWX] RE: PyWX (Python AOLserver plugin)

Titus Brown titus@caltech.edu
Wed, 13 Sep 2000 10:09:42 -0700

-> > There's no easy way to fix the current directory problem.  Just tell
-> > your CGI programmers that os.chdir() is off-limits; you may remove it
-> > from the os module (and from the posix module) during initialization
-> > of your interpreter to enforce this.
-> >
-> This is probably a good idea.

Finally, he says it ;).

-> > Are you *sure* you are using PyInterpreterState_New() and not just
-> > creating new threads?
-> >
-> Yes.

We're using Py_NewInterpreter().  I don't know how much Brent has said
(I'm not on the python-dev mailing list, something I intend to remedy)
but we have two basic types of environment: new interpreter and reused

Everything starts off as a new interpreter, created using Py_NewInterpreter().
At the end of a Web request, a decision is made about "cleaning up" the
interpreter for re-use, vs. destroying it.

Interpreters are cleaned for reuse roughly as follows (using really ugly
C pseudo-code with error checking removed):



// Add builtin module

bimod = PyImport_ImportModule("__builtin__");
PyDict_SetItemString(maindict, "__builtins__", bimod);


Some time ago, I decided not to use PyInterpreterState_New() because it
seemed unnecessary; Py_NewInterpreter() did everything we wanted and nothing
more.  Looking at the code for 1.5.2, Py_NewInterpreter():

1) creates a new interpreter state;
2) creates the first thread state for that interpreter;
3) imports builtin and sys, and sys.modules modules;
4) sets the path;
5) initializes main, as we do above in the reuse part;
6) (optionally) does site initialization.

Since I think we want to do all of that, I don't see any problems.  It seems
like the sys.argv stuff is a problem with PyWX, not with Python inherently.