[mod_python] global var on 2.7

antoine rouadec at gmail.com
Sun Jul 10 10:06:59 EDT 2005

hum, ok but I tried a few more time to access this page in different
fashions and I can say in some circonstances the processes are being
reused (and therefore my bigdict object is not reloaded, as expected)
so it is consistent with Graham explanations.

The cached module "trick"  should be more performant that the "global"
only if the modules are cached once for all the processes (and nor per
process) I guess? Anyway, I'll try and see for myself.

Should this module also use global or not? Is a simple implementation like:

def getBigDic():
  return looong_and_painful_process()

enough or should I go for :
bigdic = None
def getBigDic():
  global bigdic
  if not bigdic:
    return looong_and_painful_process()
    return bigdic

and call this from index.py with

import CacheBigdic
bigdic = CacheBigdic.getBigdic()
def index(req):

I do not need truly global var, the cached object is never modified
(and the long_and_painful_process() is already nothing but a (c)pickle

On 7/10/05, Jorey Bump <list at joreybump.com> wrote:
> antoine wrote:
> > What you are saying if that if I reload my page enought time I should
> > start re-using the bigdic object?
> No, in your environment (prefork) you can get semipersistent objects by
> creating them in modules that your published modules import, thereby
> taking advantage of module caching, but they won't be truly global. Your
> imported module should initialize the object and handle exceptions if
> you anticipate failures (I do this for database handles, which
> occassionally disappear).
> If you need to use truly global values, you are going to have to look at
> pickling, file manipulation, or some kind of database.
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list