[mod_python] Subinterpreters and index.py

Nicolas Lehuen nicolas at lehuen.com
Thu Jul 1 19:58:42 EDT 2004


Jorey Bump wrote:

> Nicolas Lehuen wrote:
> 
> > Hi,
> >  
> > I'm encoutering an unexpected behaviours while using the publisher 
> > handlers and two index.py, one in /app/index.py and one in 
> /app/subdir/index.py.
> >  
> > When I first call http://localhost/app/, /app/index.py is 
> called. Then 
> > if I call http://localhost/app/subdir/, 
> /app/subdir/index.py is called 
> > allright, but then if I try again http://localhost/app/, I 
> always get 
> > /app/subdir/index.py !
> 
> Modules are namespaces, regardless of their physical 
> location. This is very important, even within subinterpreters.

I do understand this, and that's why I think that the module defined in
/app/index.py should not be overwritten by the one defined in
/app/subdir/index.py. Maybe the namespace of the module defined by
/app/subdir/index.py should be created within the namespace of the module
defined by /app/index.py, so that the latter would inherit names from the
former ? It seems that the publisher load each .py file as modules based on
the filename only, hence the name collisions. If directories or URIs could
be taken into account, this collision problem would disappear.

> mod_python already puts the directory at the front of the 
> sys.path. You can determine this by creating a module:

[snip code]

Well, that's the first thing I tried a few month ago, but that's not the
case on my installation (Apache2 + mod_python running on Windows 2000 SP4).
Maybe this is due to the fact that I used the PythonPath directive ? I
defined it like this (in httpd.conf) :

LoadModule python_module python/mod_python.so
AddHandler mod_python .py .psp
PythonPath
"sys.path+['C:/apache/python/Lib','C:/apache/Subversion/python','C:/apache/t
rac']"
PythonHandler mod_python.publisher | .py
PythonHandler mod_python.psp | .psp
PythonDebug On

How can I benefit from the behaviour you describe while also declaring the
libraries I need on the Python path ?

Thanks for your help,

Regards,

Nicolas



More information about the Mod_python mailing list