[mod_python] importing a configuration module

Graham Dumpleton graham.dumpleton at gmail.com
Mon Jul 28 07:00:09 EDT 2008

2008/7/28 bharath venkatesh <bharathv6.project at gmail.com>:
> Hi all,
>         I am using mod python and publisher handler  for handling request ..
> I want to load to some configuration so that this configuration is used for
> all the request ...
> so  i placed the  all the configuration in a .py file and imported it .. and
> also i am doing some initialization in this file .. so i want  it to be
> imported only once ..
> but  apache reimports when  a request occurs after a gap of certain time ..
> it doesn't reimport  if the request occurs continuously .. this is
> toleratable   if i am only l loading configuration but i am doing
> initialization also .. so if want to write into a file using
> open("filename","w") .. if i place this line in the file i  am  importing
> then... the file gets truncated each time the the file is imported ... this
> is not desirable ..
> i tried even setting  PythonAutoReload off but still apache was reimporting
> the module
> i tried using PythonImport directive .. (eg PythonImport
> /home/bharath/config.py /usr/bin/python2.5 ) couldn't figure out how to get
> it work .. if i place the config.py file in a different directive than the
> directive in which the handler is placed(assuming that apache  will  import
> this module during start up as it does for library modules )  .. i am
> getting  a import error and also if i place the config.py in the same
> directory that of the handler and if import it .. apache reimports it as
> usuall ...
> how to let apache import a module only once as it does for python library
> modules  but apache should reimport it the when changes are made in the file
> that is imported ...

You misunderstand how Apache works.

Apache is a multiprocess web server, it also recycles processes and/or
creates new ones as necessary. Thus, a code file although it may be
loaded only once by a process, can be getting loading by other
processes created by Apache as well. The lifetime of these processes
can all overlap with each over and not sequential.



This is from mod_wsgi documentation, but most also applies to
mod_python. Only bit that doesn't is mod_wsgi daemon mode as no
equivalent in mod_python.


More information about the Mod_python mailing list