Many more details on import weirdness (was: Re: [mod_python] Severe problems with importing still happening.)

Sean Reifschneider jafo at tummy.com
Thu Sep 2 02:36:38 EDT 2004


On Mon, Aug 30, 2004 at 10:52:32AM -0400, Gregory (Grisha) Trubetskoy wrote:
>I've skimmed over the two messages you referenced, and it wasn't very 
>apparent what the problem is mainly due to the complexity of the 
>attributes. I think if you want this resolved, you need to work on a clean 

Ok, I've finally been able to reproduce the problem in a simple example.
Here's what I did:

   Add the following to my httpd.conf:

      Listen *:8084

      #  for debugging
      MaxKeepAliveRequests 1
      MaxRequestsPerChild  1

      <VirtualHost *:8084>
         ServerName dev.example.com
         ServerAdmin webmaster at example.com
         DocumentRoot /home/httpd/modpythonpublishertest/py/

         PythonAutoReload On
         PythonDebug On

         <Directory /home/httpd/modpythonpublishertest/py/>
            AddHandler mod_python .py
            PythonHandler foo::handler
         </Directory>
      </VirtualHost>

   /home/httpd/modpythonpublishertest/py/foo.py:

      def handler(req):
         #from mod_python import util
         import mod_python
         from package import module
         module.function(req)
         req.write('Completed')
         return(mod_python.apache.OK)

   /home/httpd/modpythonpublishertest/py/package/__init__.py:

      import module

   /home/httpd/modpythonpublishertest/py/package/module.py:

      import mod_python

      def function(request):
         mod_python.util.FieldStorage(request)

Now, restart Apache and access http://127.0.0.1:8084/foo.py  The
following is displayed:

   Mod_python error: "PythonHandler foo::handler"

   Traceback (most recent call last):

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

     File "/home/httpd/modpythonpublishertest/py/foo.py", line 5, in
   handler
       module.function(req)

     File "/home/httpd/modpythonpublishertest/py/package/module.py", line
   4, in function
       mod_python.util.FieldStorage(request)

   AttributeError: 'module' object has no attribute 'util'

If you uncomment the line "#from mod_python import util" from foo.py and
reload the URL, it will display:

   Completed

Unfortunately, the patch which "Byron Ellacott <bje at apnic.net>" posted
about a couple of days ago I can confirm does *NOT* resolve this issue.
Though it definitely sounds like a similar issue.

It seems to me that the information I posted back in May of 2004 in:

   http://www.modpython.org/pipermail/mod_python/2004-May/015678.html

has some fairly important information, it's just that it means nothing
to me.  In particular:

   <module 'jotweb.jotwebutils' from
      '/usr/lib/python2.2/site-packages/jotweb/jotwebutils.py'>
   <module
      '/var/www/jotweb/www.tummy.jotweb.jotwebutils' from
      '/usr/lib/python2.2/site-packages/jotweb/jotwebutils.py'>

In other words, it seems to have a weird path in one of the modules.
Note that in this case, "/var/www/jotweb/www.tummy.com/html" was
probably my DocumentRoot.

Note that in my testing tonight, I tried augmenting
apache.py.import_module(), and it seems to only get called for "foo",
not for mod_pyhon, of course.  I added some logging of the above, and
they're both coming up as "module 'mod_python'".  However, if I take a
dir() of it, I see that if I leave the line commented I get:

   ['__all__', '__builtins__', '__doc__', '__file__', '__name__',
   '__path__', 'apache']

and if I uncomment it I get:

   ['__all__', '__builtins__', '__doc__', '__file__', '__name__',
   '__path__', 'apache', 'util']

I believe this is fairly close to what I've seen elsewhere.  This case I
can't really reproduce outside of mod_python, but others I could.  In
other words, it was my own code that was having this problem in the
past, but if I ran the same code outside of mod_python, it would run
fine.

That's about all I know.  It seems like some sort of interaction, where
something mod_python is doing is causing something weird to happen with
standard Python imports.

Sean
-- 
 Thieves broke into Scotland Yard yesterday and stole all the toilets.
 Detectives say they have nothing to go on.
Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
tummy.com, ltd. - Linux Consulting since 1995.  Qmail, Python, SysAdmin


More information about the Mod_python mailing list