MOD_PYTHON + packages reloading

L

lukasz.f24

Hello,

I came across annoying problem during my fun with mod_python. I turned
out that mod_python load package only onca and don't care about any
changes to it. Obviously it makes sense on production server but
during development is more then annoying. I find a way to reload my
module:

m = apache.import_module(name)
reload(m)

But this solution doesn't satisfy my. Is there any way to use old good
import x.x.x or from x.x.x import y and somehow set mod_python to
autoreload packages? apache.import_module(name,autoreload=1) didn't
work.
What is more interesting if a file is in the same directory (no in the
package) i don't need to wory about reloading, python doesn't cache
it.

Please help me :)
 
D

Duncan Booth

I came across annoying problem during my fun with mod_python. I turned
out that mod_python load package only onca and don't care about any
changes to it. Obviously it makes sense on production server but
during development is more then annoying.

Have you read the mod_python manual?

http://www.modpython.org/live/current/doc-html/dir-other-par.html

5.4.8 PythonAutoReload

Syntax: PythonAutoReload {On, Off}
Default: PythonAutoReload On
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

If set to Off, instructs mod_python not to check the modification date
of the module file.

By default, mod_python checks the time-stamp of the file and reloads the
module if the module's file modification date is later than the last
import or reload. This way changed modules get automatically reimported,
eliminating the need to restart the server for every change.

Disabling autoreload is useful in production environment where the
modules do not change; it will save some processing time and give a
small performance gain.
 
L

lukasz.f24

Have you read the mod_python manual?

http://www.modpython.org/live/current/doc-html/dir-other-par.html

5.4.8 PythonAutoReload

Syntax: PythonAutoReload {On, Off}
Default: PythonAutoReload On
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

If set to Off, instructs mod_python not to check the modification date
of the module file.

By default, mod_python checks the time-stamp of the file and reloads the
module if the module's file modification date is later than the last
import or reload. This way changed modules get automatically reimported,
eliminating the need to restart the server for every change.

Disabling autoreload is useful in production environment where the
modules do not change; it will save some processing time and give a
small performance gain.

Yes I have read it. This is my config file
<VirtualHost *:80>
ServerName info
DocumentRoot D:/web/info/
<Directory "D:/web/info/">
AddHandler mod_python .py
PythonHandler index
PythonDebug On
PythonAutoReload On
AllowOverride All
Allow from All
AllowOverride All
</Directory>
</VirtualHost>

Even when autoreload is ON mod_python doesn't care about any changes
if I import something from package in traditional way :(
 
G

Graham Dumpleton

Have you read the mod_python manual?

http://www.modpython.org/live/current/doc-html/dir-other-par.html

5.4.8 PythonAutoReload

Syntax: PythonAutoReload {On, Off}
Default: PythonAutoReload On
Context: server config, virtual host, directory, htaccess
Override: not None
Module: mod_python.c

If set to Off, instructs mod_python not to check the modification date
of the module file.

By default, mod_python checks the time-stamp of the file and reloads the
module if the module's file modification date is later than the last
import or reload. This way changed modules get automatically reimported,
eliminating the need to restart the server for every change.

Disabling autoreload is useful in production environment where the
modules do not change; it will save some processing time and give a
small performance gain.

Have you read the other document:

http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html

In particular read the documentation for the import_module() function.
It clearly describes in what limited cases module reloading is
performed. It does not do it for all modules as many mistakenly
believe. It does not do any form of module reloading on Python
packages because it is impossible to do properly due to the fact that
cyclic dependencies can occur with how packages are generally
structured.

For a description of some of the issues and why mod_python 3.3 works
like it does, see the big list of problems related to module reloading
in older versions of mod_python:

http://www.dscpl.com.au/wiki/ModPython/Articles/ModuleImportingIsBroken

So, what is in 3.3 as described in documentation for import_module()
is as good as it gets. As long as you work within the constraints it
imposes you can go a long way, but don't expect miracles.

Graham
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top