[mod_python] psp_site example doesn't work

Nicolas Lehuen nicolas.lehuen at gmail.com
Mon Jan 24 02:09:02 EST 2005


On Sun, 23 Jan 2005 18:38:43 -0500, Graham Dumpleton
<grahamd at dscpl.com.au> wrote:
> Jorey Bump wrote ..
> > Zach White wrote:
> >
> > > http://beta.rvmotel.com/index/index
> > > http://beta.rvmotel.com/index.py/index
> > >
> > > Not a big deal, but not really ideal, either. It means I'll have to use
> > > AddHandler and have an index.html or index.cgi that redirects the user
> > to
> > > the real index page. From my own developing standpoint, I'd rather not
> > have
> > > to do that. But from the standpoint of the people I'm doing this for,
> > it
> > > doesn't matter.
> >
> > I use the Publisher handler exclusively, and do all of my development
> > this way, with one exception: I avoid using the name "index" like the
> > plague in module or function names! AddHandler lets you add index.html
> > to the directory if you feel you must, but it doesn't even make sense to
> > try to include index.py in the DirectoryIndex; it would be like trying
> > to put 20 versions of example.exe in a Windows directory. Start off by
> > giving all of your applications unique names and you'll avoid namespace
> > pollution issues that trip up a lot of mod_python newbies.
> >
> > To clarify, if you have a foo.py located *anywhere*, don't reuse the
> > name in another module. Choose a sensible function to start with
> > (remember, this is with Publisher in mind) and distribute the URL:
> >
> >   http://host.dom/foo/login
> >
> > I've had no issues with users misunderstanding such URLs and achieve a
> > terrific hassle-free separation between applications this way.
> > AddHandler lets me mix file types in a directory, and MultiViews lets me
> > drop the .py extension in the URL.
> 
> Possibly worth emphasising in this is the use of a common name, used
> across multiple directories, and not unique names may cause subtle
> problems with module reloading. This is why one should avoid it.
> 
> The problem here is that the mod_python module importing mechanism
> uses the "imp" module, which has the same affect as "import" statement.
> Because module imports are added into "sys.modules", you have issues
> when the same module name appears in two different directories. For
> examples, if you have "subdir1/index.py" and "subdir2/index.py".
> 
> If no "index" module has been loaded and "subdir1/index.py" is accessed,
> it will be loaded. If now "subdir2/index.py" is accessed, the mod_python
> module importing mechanism will note that the "index" module is located
> at a different path and thus will load the latter. In doing this however, it
> will override the existing "index" module already in "sys.modules".
> 
> The consequences of this are that if requests cycle between the two
> versions of "index.py", on every access there will be a module reload.
> This will be inefficient at least, but worse problems could arise if the
> two instances of the module use similar names for global variables.
> 
> Package such as mpservlets and Vampire implement their own module
> importing mechanisms in order to avoid this problem. Ie., with those
> packages it is safe to have Python code files which are named the same
> appearing in different directories managed by mod_python running
> under the same interpreter.

We had a discussion a few months ago about this issue, and I still
think it's a bug. Like Daniel Popovitch with mpservlets and you with
Vampire, I had to implement my own import mechanism to work around the
bug. I think it's time to fix it... I'll add a bug report and see what
we can do about it.

Regards,
Nicolas


More information about the Mod_python mailing list