[mod_python] Catalog of mod_python.publisher problems.

Graham Dumpleton grahamd at dscpl.com.au
Tue Jan 25 01:46:07 EST 2005


Graham Dumpleton wrote ..
> Graham Dumpleton wrote ..
> > 
> > Do we need to document properly first the perceived problems and some
> > examples of errornous behaviour? This will help to ensure we fix
> > everything and provide a basis for some tests of any new implementation.
> > I know that such information can be noted against the bug tracker item,
> > but is it easier to thrash it out here first.
> 
> FWIW, here is my personal list of problems in mod_python.publisher that
> I know about. Note that I have ignored totally the basic issue that sys.path
> makes which module you get unpredictable if import_module() is used
> directly. This is just mod_python.publisher problems which should in
> themselves be fixable whatever may eventually be done about the
> import_module() method. Let me know if you want these put on bug
> tracker as one item or three items.

Here is a fourth problem I have remembered. Although am sure that some
will say that this is expected as well. ;-(

ImportError: cannot import name publisher
------------------------------------

In a directory publisher, setup for mod_python.publisher as described in
previous email, and with same index.py. Ie.,

  import os
  def index():
    return os.getpid(),__file__

Now create a parallel directory called "handler" and in its .htaccess file add:

  SetHandler python-program
  PythonHandler mptest
  PythonDebug On

The mptest.py file in that directory should read:

  from mod_python import apache
  import os

  from mod_python import publisher

  def handler(req):
    req.content_type = "text/plain"
    req.send_http_header()
    req.write(str((os.getpid(),__file__)))
    return apache.OK

Restart Apache to clear caches and access "handler" and "publisher"
directories in that order. One gets:

  (747, '/Users/grahamd/Sites/handler/mptest.py')
  (747, '/Users/grahamd/Sites/publisher/index.py')
  (747, '/Users/grahamd/Sites/handler/mptest.py')
  (747, '/Users/grahamd/Sites/publisher/index.py')
  
Okay, everything is fine.

Now restart Apache to clear caches and access "publisher" and then
"handler". Ie., in reverse order. One gets:

  (761, '/Users/grahamd/Sites/publisher/index.py')

  Mod_python error: "PythonHandler mptest"

  Traceback (most recent call last):

    File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 296, in HandlerDispatch
      log=debug)

    File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 421, in import_module
      autoreload=autoreload,log=log,path=path)

    File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-packages/mod_python/apache.py", line 474, in _unsafe_import_module
      module = imp.load_module(mname, f, p, d)

    File "/Users/grahamd/Sites/handler/mptest.py", line 4, in ?
      from mod_python import publisher

  ImportError: cannot import name publisher

The way in which mod_python.publisher is loaded as PythonHandler,
if done before being imported explicitly using "import", screws up
that latter import.

I know some will scream that I am mixing "import" and "import_module()",
but since mod_python.publisher is installed into "site-packages", one
should expect it to work with "import". Whether it does is order dependent.

Because I use mod_python.publisher in Vampire for its user authentication
stuff, this problem means that if using Vampire and elsewhere also wanting
to use mod_python.publisher as PythonHandler, that the Vampire area
should be setup with its own PythonInterpreter instance.

Having now remembered this problem, as a workaround in Vampire I
should probably go and use:

  publisher = apache.import_module("mod_python.publisher")

instead. At least that way it will work all the time. :-)

I know my wanting to use internals of mod_python.publisher is the
exception, but these sort of strange things shouldn't by right happen.

Graham






More information about the Mod_python mailing list