[mod_python] Re: import requires apache restart?

Graham Dumpleton graham.dumpleton at gmail.com
Fri Oct 19 01:21:45 EDT 2007

On 19/10/2007, apocalypznow <apocalypznow at gmail.com> wrote:
> But does apache.import_module() handle .pyc or .pyo files?

In mod_python 3.3.1 the answer is no in all cases.

In mod_python 3.2.X, mod_python.publisher didn't use
apache.import_module() and used its own module importer which didn't
generate or use .pyc or .pyo files.

In mod_python 3.2.X and older versions, how apache.import_module()
used .pyc/.pyo files gets a bit messy as it was broken and thus not
reliable in the way it dealt with .pyc/.pyo files. I'd rather not have
to go back and work out the ways it was wrong again just to explain
it. Just trust me when I say to use the latest version, it is more

In terms of what you are trying to do, yes you can supply just
.pyc/.pyo files, but they must be installed as part of a package or as
a module on sys.path somewhere. If you need to change those files, you
must restart Apache, they will not be reloaded automatically. You also
shouldn't rely on using the base Python 'reload' mechanism either as
it doesn't entirely always work either and why it is being removed in
Python 3.0.


> Graham Dumpleton wrote:
> > This is quite normal behaviour. Standard Python modules and packages
> > are not candidates for reloading. Read the documentation for
> > import_module() in:
> >
> >   http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html
> >
> > This explains the line of separation between when mod_python can and
> > can not automatically reload modules.
> >
> > Graham
> >
> > On 19/10/2007, apocalypznow <apocalypznow at gmail.com> wrote:
> >
> >>I've noticed something, and I wonder if someone could please confirm if
> >>this is the correct behaviour.  In my httpd.conf file, I've included the
> >>path to a location where my python files are using the PythonPath
> >>directive.  In my handler code file, I issue a standard "import"
> >>statement rather than the mod_python (or for that matter,
> >>vampire.importModule) versions of the import.  To give light protection
> >>  (against authoring infringement) to my source files, after I
> >>py_compile them, I delete the original .py files.
> >>
> >>Even after changing the source of the files in the PythonPath, and after
> >>py_compiling them, and after removing the original .py files, I found
> >>that an Apache restart is required for the changes to be effected.  Does
> >>this make sense?  If that is the case, is there some copy of the python
> >>file being made by mod_python somewhere?
> >>
> >>_______________________________________________
> >>Mod_python mailing list
> >>Mod_python at modpython.org
> >>http://mailman.modpython.org/mailman/listinfo/mod_python
> >>
> _______________________________________________
> 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