[mod_python] The new module loader

Dan Eloff dan.eloff at gmail.com
Sat Apr 22 15:22:36 EDT 2006


Well for now I'm putting pyserver back into a package, and dumping it
into the site-packages directory again.

In an ideal world pyserver doesn't need to be relaoded, it's more of a
supporting framework for my web applciations and since it needs to be
accessible from all my web applications, it makes some sense for it to
be located on sys.path.

In the real world pyserver is not stable yet, and changes frequently,
and I'll miss the reloading ability. But hey that's why I have restart
apache on hotkey. CTRL+ALT+A and hit refresh.

In my case the only place I use mod_python is through pyserver and
it'd be nice to add directories to the search path with global defines
in the apache config for cases like this.

-Dan

On 4/22/06, Dan Eloff <dan.eloff at gmail.com> wrote:
> It works! Nice feature, I don't see any trouble with it being the way
> it is, maybe if you just added some __debug__ only code that squeals
> if the same module is imported with a different search path.
>
> Although something that would be nice is a feature like python has
> with sys.path, that is the ability to globally add directories to the
> search path (through code and through the apache config maybe.) I
> would still like the ability to add the pyserver directory globally to
> every module's search path, because for me, every module that
> mod_python loads should have access to it.
>
> I didn't realize you lived in the Australia, I just assumed you were
> in the US. You're probably fine. Right now in North America the
> housing bubble has just burst, but not many have figured it out yet.
> When they do, most of those people who are buying real estate right
> now are going to get burned. The real estate market is cyclical, so
> it's not a big deal, more of an overdue correction, but I wouldn't
> want to be the one having to pay for that. On the bright side, it's
> good news for the stock market.
>
> -Dan
>
> On 4/22/06, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
> >
> > On 22/04/2006, at 4:08 PM, Dan Eloff wrote:
> >
> > >> How are the files in this directory (_config.py) being imported in
> > >> the first place?
> > >> Is your pyserver.py file importing them explicitly using
> > >> apache.import_module()?
> > >
> > > Yes, that's exactly it.
> >
> > If your pyserver.py is effectively acting as a dispatcher for
> > multiple pages
> > based on URL, and it is using apache.import_module() to load an actual
> > handler module file from your "web" directory by full path name, ie.,
> > something like:
> >
> >    stub = posixpath.splitex(req.path_info)[0]
> >    file = os.path.join("C:/My Documents/PYROOT/web", stub) + ".py"
> >    module = apache.import_module(file)
> >
> > Change it to:
> >
> >    directory = os.path.dirname(__file__)
> >    stub = posixpath.splitex(req.path_info)[0]
> >    file = os.path.join("C:/My Documents/PYROOT/web", stub) + ".py"
> >    module = apache.import_module(file, path=[directory])
> >
> > It is important you be providing a full pathname as first argument to
> > the
> > apache.import_module() as by doing so it triggers a special different
> > interpretation for the "path" argument.
> >
> > Namely, when the module is specified by a full or absolute pathname,
> > as opposed to just the module name, the "path" argument becomes a
> > search path which is embedded within the loaded module and which
> > is consulted when sub imports are done from within that module.
> >
> > Using this feature, you can then embed the directory the config module
> > is in as part of the module search path for the "web" module and using
> > the "import" statement or apache.import_module() to load it should
> > then work.
> >
> > Note that the search path is only embedded within the module directly
> > loaded by apache.import_module() when this is done. The search
> > path is not inherited by any modules it may then in turn import.
> >
> > Also note that this feature is an area which still has to be properly
> > thought out as to how it should work or be accessible. How it is
> > currently exposed is handy in some circumstances, but possibly
> > not as generally useful as it could be. How the ability to use it is
> > exposed may well change in time. One has to be really careful though
> > with such a feature because of the possibilities of introducing
> > unpredictable behaviour from when a module is imported from
> > different places with potentially different search paths defined. This
> > sort of path difference problem is a big problem with the current
> > importer, so rather want to avoid it.
> >
> > I'll probably talk again about these search path issues when I finally
> > get around to addressing Jorey's email.
> >
> > > If you want some unasked for info on the housing, ....
> >
> > Which country is this???? Doesn't quite reflect my situation here in Oz.
> > Anyway, with all those property terms in there, probably lucky my spam
> > filter didn't flag it. :-)
> >
> > Graham
> >
>



More information about the Mod_python mailing list