[mod_python] sporadic import errors...

Guido van Rossum guido at python.org
Mon Dec 17 16:01:35 EST 2001


> okay, i'm running Python 2.1.1, mod_python 2.7.6, and apache 1.3.19
> under Linux 2.2.14. the mod_python module is build statically.
> 
> after hitting our app a couple of times, i sporadically receive the
> following error:
> 
> 'import site' failed; traceback:
> Traceback (most recent call last):
>   File "/usr/local/lib/python2.1/site.py", line 60, in ?
>     import sys, os
>   File "/usr/local/lib/python2.1/os.py", line 54, in ?
>     __all__.extend(_get_exports_list(posix))
>   File "/usr/local/lib/python2.1/os.py", line 35, in _get_exports_list
>     return list(module.__all__)
> AttributeError: 'posix' module has no attribute '__all__'
> make_obcallback(): could not import mod_python.apache.
> make_obcallback(): could not call init.
> 
> and i'm having a terrible time isolating what could be causing this to
> occur.
> 
> interesting things which could be related:
> 
> o multiple instances of the app are running under the same apache with
> different <Directory> tags handling the different apache/mod_python
> settings
> 
> o i have PythonInterpPerDir turned on
> 
> o the problem seems most easily exaccerbated by running multiple
> scripts simultaneously

Here's my analysis of the case.  Looking at the source code of os.py:

def _get_exports_list(module):
    try:
        return list(module.__all__)
    except AttributeError:
        return [n for n in dir(module) if n[0] != '_']

the AttributeError should be caught -- but it isn't!  I think this is
because each Python interpreter instance initializes its own copy of
the exceptions -- but store them in a global shared by all instances
running in the same process!

> the biggest problem i'm having (besides the error itself) is that i
> can't figure out any way to tell which subinterpreter i am in when
> these errors happen. i've poked through the documentation and
> pythonrun.c to no avail.

Can you try this with Python 2.2c1?  I think we've fixed it there.  If
you can't try 2.2c1, try the patch to pythonrun.c from rev 2.143 to
2.144:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Python/pythonrun.c.diff?r1=2.143&r2=2.144.

--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Mod_python mailing list