[mod_python] persistant variables

Ian Clelland ian at veryfresh.com
Fri Mar 22 10:09:59 EST 2002

On Fri, Mar 22, 2002 at 05:18:50PM +0100, Alexander Steinert wrote:
> > How can I force mod_python to only have one instance of the variable? Or
> > should I be trying to do this in an entirely different way?
> > 
> > I can set Apache to only start with one server (which makes it work),
> > however it will spawn more servers if it gets two hits at the same time, so
> > this won't really work.
> I thought about this topic a few weeks ago and came to the conclusion
> that that you can't force the wished behaviour (if apache is forking).
> You need persistent storage in a DBMS or a file and must take care of
> concurrent accesses.

I've come to the same conclusion myself, after a fair bit of 
experimentation and research (there was a lengthy discussion on this 
list about a year ago: 
http://www.modpython.org/pipermail/mod_python/2001-April/001254.html ).

Because Apache (on Unix) forks new processes for its children, they 
must necessarily run in isolated memory spaces. However, since each 
child process is long-lived, you can retain some persistent data (like 
a database connection handle) between requests /to that child/. It's 
not quite the same thing as global persistent data, but it works for 
some applications.

Apparently mod_perl developers can get around this limitation by using 
the IPC::Shareable module -- has anybody in the Python community done 
any work on something similar?

<ian at veryfresh.com>

More information about the Mod_python mailing list