mod_python: How to make a single object available to all instances?

Robert Brewer fumanchu at amor.org
Sat Jul 17 16:48:29 EDT 2004


Trond wrote:
> I have a dictionary which is ca 40mb in size. I need this dict to be
> available for each apache/mod_python thread. But since it is so big, I
> cannot allow each thread to retain a copy of the dict, and it takes
> too much time to load the file from db/hd. So I wonder if there is any
> methods for making the dictionary "global" for all threads, like an
> enviromental variable or something.

mod_python won't reload modules (as long as you keep *a* thread alive, I
think); therefore, you can put your dict in a module:

# myapp/env.py

bigdict = {}

On the first request to your app, start a new thread with a reference to
that module; subsequent imports will find env.py in sys.modules and
won't reload, and therefore won't reinit your bigdict.


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org



More information about the Python-list mailing list