[mod_python] Force reload?

Graham Dumpleton grahamd at dscpl.com.au
Thu Feb 3 23:22:22 EST 2005

Shawn Harrison wrote ..
> I'm curious about this. I just whacked up the following function over
> lunch today, following my own advice, and tested it a bit just now. The
> function seems to work just fine in all the use cases (though I didn't
> do formal unit testing).
> Is there any reason I'm not seeing why this function won't solve the 
> reload problem, if used in place of all import statements in the 
> application?

It will not work where there are multiple levels of imports. Consider the following
where "a.py" is the top level content handler that all access are done through it.

  # module c.py


  # module b.py

  from mod_python import apache

  c = apache.import_module("c",autoreload=1)


  # module a.py

  from mod_python import apache

  b = apache.import_module("b",autoreload=1)

When "a.py" is loaded internally by mod_python, it is also done by the
apache.import_module() method.

If you modify "a.py", mod_python will detect it and it will get reloaded
automatically provide PythonAutoReload is "On".

If you modify "b.py" nothing happens. This is because there is no depth
search to determine that anything used by "a.py" was modified.

This at least will be the case where the import is done at global scope.
If on the other hand you had the following:

  # module a.py

  from mod_python import apache

  def handler(req):
    b = apache.import_module("b",autoreload=1)

This will work better as each time the handler is called to process the
request, it effectively asks for the sub module. If "b.py" hasn't changed,
then it comes from the cache. If "b.py" has changed, then it will be

If "c.py" is now modified, again, nothing gets reloaded. To fix this would
mean that every function in "b.py" that you might call that uses stuff
from "c.py" would have to be changed to ask for the "c" module each
time. Where "b.py" is a bunch of utility functions, this becomes a mess.
It also precludes simple global data in "b" that is somehow dependent
on "c", as it isn't easy to refresh global data in "b" which is based on "c"
in each function if "c" happened to get reloaded.

The current mechanisms available are thus not very effective in assisting
with the problem.

I could mention Vampire yet again and how it has solved this problem
and many other module loading issues, but based on the continuing
followups which show that no one has read what I said, I will refrain
from doing so ..... ;-(


More information about the Mod_python mailing list