mod python: How to make a single object available to allinstances?

Trond tamyk at online.no
Sun Jul 18 21:08:30 CEST 2004


Yes, I am aware that the file will be initiated once, but according to
the memory used, each thread got a copy of the bigdict dictionary. So
the module is initiated once, and a copy made for each thread. Correct
me if I am wrong. Of course, If I can delete the module from the
thread after each task, this is no problem, but deleting objects in
python isn't allways easy done...

"Robert Brewer" <fumanchu at amor.org> wrote in message news:<mailman.527.1090097580.5135.python-list at python.org>...
> 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