[mod_python] Problems re-using a child's python interpreter

Diedrich Vorberg diedrich at tux4web.de
Wed Oct 3 18:19:16 EST 2001

mod_python: Version 2.7.6
apache: 1.3.14

Hi folks,

I wrote a sort of minimal 'content management helper', that translates
XML to html and inserts dynamically created content on the
fly. Nothing fancy, but it works - thought I, untill I found out it

My python handler looks like this:

from mod_python import apache
import logic.util

def handler(req):
    req.content_type = "text/html"

    rendering = logic.util.getRendering(req.filename, req)
    rendering = logic.util.insertDynamicContent(req, rendering)
    return apache.OK

The directory it's supposed to work in is:

<Directory /var/public_html/ted-magoo.de/domains/some-domain.de/www>
  AddHandler python-program .xml
  PythonHandler roteerde
  PythonDebug On
  DirectoryIndex index.xml
  PythonInterpPerDirectory On

There is a 'logic' dir below the 'www' directory that contains a
__init__.py and a util.py to make the import above work. And so it
does until I created a second domain with the same setup and (nearly)
the same files. I can access both directories at a time, but as soon I
access one and than the other I get an apache error like:

make_obcallback(): could not import mod_python.apache.
make_obcallback(): could not call init.
[Wed Oct  3 15:42:38 2001] [error] [client] python_handler:
make_obcallback returned no obCallBack]

I figured out that this has something to do with python being unable
to find some modules. So I set a very long PYTHONPATH width all module
paths on it before starting apache. Now I get all sorts of unrelated
module-not-found errors. However, this only happens sometimes! Every
second request or so gives me an error message or an error 500.

My attempts debugging seem to indicate that errors do not occur when
apache created a new sub-process and with it a new python interpreter
to answer the request. So the only solution I came up with is setting

MaxRequestsPerChild 1

in http.conf. This lets apache sub-processes die as soon they answered
a request. Of course it creates an enormous overhead.

I'd greatly appreciate any ideas you have to solve the problem. I am
sure you are facing similar problems when creating complex web
applications with mod_python. What design patterns do you use to do


           _..._                            Diedrich Vorberg
         .'     '.
        /  _   _  \                         http://www.tux4web.de
        | (o)_(o) |                         info at tux4web.de
         \(     ) /            .---.
         //'._.'\ \           /     \       Internet Dienstleistungen
        //   .   \ \          \. at -@./       und 'Consulting'.
       ||   .     \ \         /`\_/`\
       |\   :     / |        //  _  \\      Linux Rules!
       \ `) '   (`  /_      | \     )|_
     _)``".____,.'"` (_    /`\_`>  <_/ \
     )     )'--'(     (    \__/'---'\__/
      '---`      `---`

More information about the Mod_python mailing list