[mod_python] Initial configuration and persistence

Richard Lewis richardlewis at fastmail.co.uk
Mon Jun 5 11:16:41 EDT 2006

Hi there,

I'm new to mod_python and have nearly finished writing a module implementing a 
subset of Apache Cocoon's functionaiity, providing URI pattern matching, 
Berkeley DB XML-powered XQuery and libxslt-powered XSLT transformations.

There are a couple of things I'm stuck on, though.

My handler works fine when tested from the command line and it also works from 
Apache when I include my special XML configuration file directly in the 
handler source code. However, I'd like to be able to have the configuration 
file separate from the handler source code so that I can use the handler 
unaltered for multiple sites.

What I can't do is work out how to pass the file name of the XML configuration 
file as a parameter to mod_python from my Apache configuration file when my 
handler is initially loaded. I've added an Apache SetEnv directive and I can 
see it from apache.config_tree() but I can't work out how to get its value.

My VirtualHost configuration currently looks like this:

NameVirtualHost *
<VirtualHost *>
    ServerName www.studios.uea.ac.uk
    DocumentRoot /var/www-studio
    SetHandler mod_python
    PythonDebug On

    <Directory /var/www-studio>
        SetEnv sitemap_config sitemap.xml
        PythonHandler sitemap

Any ideas how to get that SetEnv's value from inside sitemap.py?

The other thing I'm stuck on is implementing persistence. I currently have my 
DB XML manager, some compiled XSLT stylesheets and other configuration data 
stored as global variables in my handler. However, from my Apache log, it 
looks as though it reloads my handler module every time a request is made, 
thus reloading the database connection, re-compiling the stylesheets etc. 
when I'd rather they just persisted between requests. Is there a way of 
making them persist? Or is it just my imagination that they are being 

Richard Lewis
Sonic Arts Research Archive

More information about the Mod_python mailing list