[mod_python] erratic import errors with mod_python

Detmar Meurers dm at julius.ling.ohio-state.edu
Sat Jun 3 14:36:00 EDT 2006


Hi,

I'm using mod_python's publisher handler to load a .py file using
the usual

AddHandler python-program .py
PythonHandler mod_python.publisher
PythonDebug On

.htaccess specification in the directory in which the .py file
resides. That .py file imports some other modules, both standard ones
and some auxiliary functions I wrote and put into a separate file.

Usually the code executes fine, but every five or so times the page
is loaded (without changing anything, e.g. just doing several
reloads in a row), I get the error that mod_python for some reason
cannot find one of the modules that is being imported (namely the
file with the auxiliary functions, called tagarela_util.py, which is
in the same directory). I'm including an example error message
below.

This error never seems to appear for the standard modules I import,
(or when I put that file into the python2.4/site-packages which is 
in sys.path), so I suspect that it has something to do with the way
mod_python seems to use the .htaccess files to determine which
directory to add to the sys.path?

I very much hope someone can explain this erratic behavior and how I
can fix it - as it stands the only way I found to avoid these
occasional errors arising when importing modules is to put
everything into the same file, i.e. to avoid importing modules,
which naturally leads to massive code duplication and
non-modularity.

Any suggestions would be much appreciated!

Best,
Detmar

--
Detmar Meurers, Associate Professor, Dept. of Linguistics, OSU
201a Oxley Hall, 1712 Neil Avenue, Columbus OH 43210-1298, USA
http://ling.osu.edu/~dm/                 GnuPG key on web page

****Server used:

'SERVER_SOFTWARE': 'Apache/2.2.0 (Unix) mod_ssl/2.2.0 OpenSSL/0.9.8a DAV/2 mod_python/3.2.8 Python/2.4.2'

(Errors appears with a variety of browsers, so seems to be independent
of that.) 

****Error message:

Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

  File "/opt/local/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
    result = object(req)

  File "/opt/local/lib/python2.4/site-packages/mod_python/publisher.py", line 204, in handler
    module = page_cache[req]

  File "/opt/local/lib/python2.4/site-packages/mod_python/cache.py", line 82, in __getitem__
    return self._checkitem(name)[2]

  File "/opt/local/lib/python2.4/site-packages/mod_python/cache.py", line 124, in _checkitem
    value = self.build(key, name, opened, entry)

  File "/opt/local/lib/python2.4/site-packages/mod_python/publisher.py", line 77, in build
    return ModuleCache.build(self, key, req, opened, entry)

  File "/opt/local/lib/python2.4/site-packages/mod_python/cache.py", line 371, in build
    exec opened in module.__dict__

  File "/home/dm/public_html/icall/tagarela/activities/Reading/index.py", line 3, in ?
    from tagarela_util import _get_session, _file2string

ImportError: No module named tagarela_util



More information about the Mod_python mailing list