[mod_python] Initial configuration and persistence

Colin Bean ccbean at gmail.com
Mon Jun 5 13:45:48 EDT 2006


Hi Richard,

Here's a couple of things to address your second question.  If you're
seeing messages in your error logs like "(re)importing module *your
handler*", this doesn't necessarily mean that the module was reloaded
and your global persistence was lost; it's a diagnostic message
generated when you've enabled PythonDebug.
One method that I've found useful for determining when global code is
executed is to add a print statement in the global scope right after
setting up your persistent stuff (to print to the error log without
having a request object available, you can do something like this:
http://www.modpython.org/FAQ/faqw.py?req=edit&file=faq02.003.htp ).
This will give you a much better idea of when your modules are being
reloaded.

This will behave differently depending on which platform you're using.
 With a prefork MPM, the first several requests after you've restarted
will create a new process with a new interpreter, so you'll see your
persistent objects get created several times before an existing
interpreter handles your request.  If you post your platform /
version, somebody can probably give you more specific advice.

HTH,
Colin


On 6/5/06, Richard Lewis <richardlewis at fastmail.co.uk> wrote:
> 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
>     </Directory>
> </VirtualHost>
>
> 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
> reloaded?
>
> Cheers,
> Richard
> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-
> Richard Lewis
> Sonic Arts Research Archive
> http://www.sara.uea.ac.uk/
> -=-=-=-=-=-=-=-=-=-=-=-=-=-
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list