[mod_python] apache.import_module picks wrong module

Kamil Niechajewicz kamil at nvstudio.pl
Thu Mar 25 17:30:11 EST 2004


On Thu, 25 Mar 2004 16:56:59 +0200
Toms Baugis <toms.baugis at tietoenator.com> wrote:
<cut>

I've had somehow similar problem. It made me crazy one day.
I'll try to explain it in detail now.

I had one VirtualHost declaration, and under it I had two
<Location> statements:

<Location /app1>
    SetHandler python-program
    PythonHandler myhandler 
    PythonDebug on
    PythonPath "sys.path + ['/path/to/app1/']"
</Location>

and

<Location /app2>
    SetHandler python-program
    PythonHandler myhandler
    PythonDebug on
    PythonPath "sys.path + ['/path/to/app2/']"
</Location>

now the directory structure:

upper_dir/

    app1/
           templates/
                  template1.xsl
                  index.xsl
 
           myhandler.py
           BaseForm.py
           BaseField.py
           something.py
    app2/
           templates/
                   template2.xsl
                   index.xsl
           myhandler.py
           BaseForm.py
           BaseField.py
           something_different.py

when I had only one application running under this VHost 
everything was fine. but when I added the second app, 
which was in totally different directory, but had few
files that had the same name like files from first
application, something started to go wrong.

usualy application worked fine, but sometimes strange
errors happened, like reporting runtime error that
SHOULD NOT happen. suddenly I noticed that applications
are somehow messing their paths? or something - there
was a random chance that app1 will mistake myhandler.py
from app1/myhandler.py and instead of using it, it will
load app2/myhandler.py, because it had the same name.
but path declarations are different for every app, so
how such mistakes were possible? the same problem happened
with templates, sometimes wrong template was loaded.

is that a matter of mod_python? my wrong apache conf
directives, or apache itself?

actually i've renamed all files that had the same names
in both applications to some, so that they all differ 
now and are not messed, but it cost me alot of work
that shouldn't be necessary. 

how could i solve this problem in the future, so that
i woulnd't have to rename all files? for me its quite
logical that some files can have the same names in
different apps-directories, and apache/modpython/whatever
shouldn't mistake them when it has directives that tell
'use this path for /app1 and this path for /app2'. i
guess that the randomness of those errors was a result
of apache-children, sometimes i ran into thread that 
had this bad configuration and everything was messed,
and sometimes i could see the page properly.

with regards,
K.


More information about the Mod_python mailing list