[mod_python] persistent, reliable globals

Erik mod_python at 24ksoftware.com
Mon Mar 8 01:10:54 EST 2004

On Mon, 8 Mar 2004, David Geller wrote:

> I would like to set a global variable (in memory) from a module. I would
> then like to access this same global variable susequently by other
> modules at any other time, and have the value that was set there to be
> there (until, of course, Apache is restarted).
> I have tried several ways of doing this, and it doesn't seem to be
> reliable - i.e., sometimes the global variable is set when I look at it,
> and sometimes it is still at its original state.
> What am I doing wrong (or right)?


New to the list and mod_python in general, but it sounds like you will
only be able to pull this off if you are using a threaded Apache.
Again, I'm new so I could be wrong.

If you're stuck with a forked Apache, then you could try using
something from the IPC toolbox: shared files, shared memory, messages,
etc.  I would pickle whatever you wanted shared to some temp file and
have your code check for that file and define it if does not exist.
That approach has some dangerous aspects to it.  The threaded Apache
approach sounds much better.

Best regards,

More information about the Mod_python mailing list