[mod_python] Beginner documentation -- suggestion

NLH AS post at nlhas.no
Sat Nov 23 12:54:36 EST 2002


I've just installed mod_python and converted a cgi application. During this
process I've spent most of my time finding out what happens where -- the
actual conversion fell into place quickly when I understood the main
framework. Everything is in the documentation, but I'd have appreciated a
simple explanation along the lines of the following (which may well be
wrong!) somewhere in the tutorial. Perhaps something like this can be
worked into the next edition of the documentation?

pm


++++++ What happens where in a "out-of-the-box" Apache/mod_python setup:

At startup or at the first call to a mod_python handler Apache loads the
Python interpreter and the import modules at the top of the handler's
module file.

Each call to the handler is executed in an Apache child process with a
separate Python subinterpreter instance. It is not possible to share global
variables between Apache's child processes (so sharing a global database
connection is not possible for example), and there is no means of
predicting whether Apache will start a new process or re-use an existing
process for any given call to the handler. [>> pointer to information about
how Apache does this, how many child processes can be started, etc.?].

Global variables within the handler's module will be available to all calls
to the handler that are routed to the same Apache process. This could be
used to maintain and re-use a database connection per child process. 

Local variables within the handler are local to each call to the handler
[and are eventually garbage-collected in the normal way?].

Mod_python will check whether the top level python module (containing the
handler) has been changed and re-load if necessary. Imported modules are
not checked, and the only 100% certain way of ensuring that updated modules
are reloaded in all child processes is to stop and re-start Apache.

It is possible to tweak various aspects of this behaviour -- for example
Apache can be compiled to only ever start one child process (which would
enable global variables), but this would entail significantly poorer
performance.
+++++
   



More information about the Mod_python mailing list