server wide variables

Graham Dumpleton Graham.Dumpleton at gmail.com
Mon Jun 25 20:38:57 EDT 2007


On Jun 26, 10:29 am, Graham Dumpleton <Graham.Dumple... at gmail.com>
wrote:
> On Jun 26, 1:29 am, Jay Sonmez <meti... at gmail.com> wrote:
>
> > I want to be able to save some server variables as long as Apache runs
> > on the server (mod_python).
>
> > How is that possible in Python?
>
> It depends on whether you expect all Apache child processes for that
> server to be able to access the data and for the data to be able to
> survive the killing off and start up of individual Apache child
> processes.
>
> For background on some of the issues read:
>
>  http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreter...
>
> Saving data in os.environ is not recommended even if they have to
> survive just within the context of that specific interpreter within
> that process, as os.environ access and update is not thread protected
> and Apache child processes may be multithreaded.

Before someone decides to shoot me down, yes I know that dictionaries
themselves are thread safe and thus os.environ itself is thread safe.
In making that comment I am looking more at the higher level locking
aspects of a combined set of data, ie., the same as you might have for
global data in a module and what is required to protect that in the
presence of multiple threads. The os.environ dictionary being what it
is, people may not appreciate the need that locking may still be
required if one is going to use it as a means of holding data that can
change over time. In short, os.environ simply shouldn't be used for
that anyway.

Graham




More information about the Python-list mailing list