[mod_python] loading configuration

Bart scarfboy at gmail.com
Mon Jul 14 04:04:02 EDT 2008

I haven't used mod_wsgi yet so I don't know how much this applies to
it, but in mod_python my solution would probably be to put all my
configuration in variables in a config.py file and use the existing
mod_python reloading behaviour of reloading it *only* when its
modification date changes (...meaning whenever you edit it).

Note that if you do this, you want to explicitly call that
config.py-reloader function in every handler, so that it will check
every time. The check alone without it having to reload is pretty
light -- and as light as you're going to get if you want it fully
automatic, since you do want it to continually check the disk (and OS
caches are nice for this sort of thing).

(I'd personally move the reloading check into a decorator to keep that
reloader code in use in a single place instead of pasting it inside
each handler. For me that makes sense anyway, since I already use
decorators to apply Unicode conversion, selectively do form parsing
and such.)

I think you want to avoid having to duplicate this with your own
custom config-reloading code, since doing it yourself means you have
to think about handling per-child *and* as soon as possible, which is
annoying when you want to force a reload from code, since you would
probably hand that wish in via a handler (in a apache single child)
and would then have to communicate that wish somehow. (the way the
reloader uses mtime sounds like a handy solution to this, and if you
can just use it without any custom hacks, all the better...)


2008/7/14 bharath venkatesh <bharathv6.project at gmail.com>:
> hi everyone,
>                     I want to load certain configuration from a
> configuration file  when a appache starts in mod python or mod wsgi  using a
> function take for example load_config() .. i don't want to include this
> load_config function inside handler as i don't want it to  execute every
> time.. and  also  when ever changes are made in the configuration file i
> should be able to load the changed configuration with out restarting appache
> ... can any one tell me how this can be done ...
> bharath

More information about the Mod_python mailing list