[mod_python] The new module loader

Dan Eloff dan.eloff at gmail.com
Fri Apr 21 02:48:16 EDT 2006


Thanks a bundle Graham, I get the gist of it. Tomorrow I'll back everything
up and then start reworking it with all that in mind. Much appreciated. The
pyserver stuff wasn't being reloaded because it's in site-packages, and the
rest of the stuff was being loaded *AFTER* being placed in sys.path. I did a
pretty good job of shooting myself in the foot there. I'll fix it all up and
give it another go and let you know what happens.

You're right about the packages too, other than as a namespace and for
convenience, I don't need it, and it makes more sense for it to live
elsewhere. You put an awful lot of thought into this, I think it will be the
death of all those auto reload woes.

Thanks again,
-Dan

On 4/20/06, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
>
> Graham Dumpleton wrote ..
> > Dan Eloff wrote ..
> > > <Directory />
> > >     SetHandler mod_python
> > >     PythonHandler PyServer.pyserver
> >
> > The new module importer completely ignores packages as it is practically
> > impossible to get any form of automatic module reloading to work
> > correctly with them when they are more than trivial. As such, packages
> > are handed off to standard Python __import__ to deal with. That it even
> > finds the package means that you have it installed in sys.path. Even if
> > it was a file based module, because it is on sys.path and thus likely to
> > be installed in a standard location, the new module importer would again
> > ignore it as it leaves all sys.path modules up to Python __import__
> > as too dangerous to be mixing importing schemes.
> >
> > Anyway, that all only applies if you were expecting PyServer.pyserver to
> > automatically reload upon changes.
>
> BTW, that something outside of the document tree, possibly in sys.path,
> is dealt with by Python __import__ doesn't mean you can't have module
> reloading on stuff outside of the document tree. The idea is that if it is
> part of the web application and needs to be reloadable, that it doesn't
> really belong in standard Python directories anyway. People only install
> it there at present because it is convenient.
>
> The better way of dealing with this with the new module importer is to
> put your web application modules elsewhere, ie., not on sys.path. You then
> specify an absolute path to the actual .py file in the handler directive.
>
> <Directory />
>      SetHandler mod_python
>      PythonHandler /path/to/web/application/PyServer/pserver.py
>      ...
>
> Most cases I have seen is that people use packages purely to create a
> namespace to group the modules. With the new module importer that
> doesn't really need to be done anymore. That is because you can
> directly reference an arbitrary module by its path. When you use the
> "import" statement in files in that directory, one of the places it will
> automatically look, without that directory needing to be in sys.path,
> is the same directory the file is in. This achieves the same result as
> what people are using packages for now but you can still have module
> reloading work.
>
> If you need a working example of this let me know.
>
> Graham
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20060420/7ec81dd4/attachment.html


More information about the Mod_python mailing list