Nicolas Lehuen
nicolas at lehuen.com
Thu Jul 1 13:02:07 EDT 2004
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 ! Well, it turns out it's a FAQ, listed here : http://www.modpython.org/FAQ/faqw.py?req=show&file=faq02.016.htp The problem is that if I want to share data between different pages, for instance a DB connection pool (which is one of the purpose of using mod_python with one interpreter per application), then I have to make sure that all those pages have a different name, so I lose the ability to have an index.py in any subdirectory... Plus, if my app begins to grow, keeping in mind this limitation is more and more difficult ("damn, did I ever use 'validation.py' as a module name ???"), all the more with the fact that the bug is quite surprising in its behaviour (no warning message, no error, no nothing). At least, this should be written in big bold red prints in the documentation. This is so unexpected and so big that I think every serious mod_python user should be aware of this and design his/her applications AROUND this bug (by having a clever naming scheme, de-modularising the app etc.). Maybe it would be possible to overcome this limitation if mod_python named and loaded the page modules according to their path relative to the place where a PythonInterpreter or PythonHandler (when PythonInterpPerDirective is On) was last defined. So, if I define "PythonInterpreter myapp" in /app, /app/index.py would be loaded as the 'index' module and /app/subdir/index.py would be loaded as the 'subdir.index' module. Likewise, maybe such an improved behaviour could enable us to do something which is AFAIK quite difficult right now : importing modules relative to the current interpreter (maybe by automatically adding the directory where the interpreter was defined to sys.path). Say I've got a utility module /app/utils.py, I could use it in /app/index.py and /app/subdir/index.py by importing 'utils'. Best regards, Nicolas Lehuen
|