[mod_python] Any support for on-time Initialization?

Daniel West dwmp at opti.cgi.net
Mon Feb 2 12:29:56 EST 2004


The best way to setup database connections is just to wait for the first 
request to come in.  Keep your database connection in a module name space 
that all of your pages share and it'll persist between connections so long 
as you don't explicitly close it.  Once you import a module it stays in the 
interpreter name space between requests so future requests have access to 
the module without having to load it again.

If you're interested in keeping "pools" of database connections then you 
may be considering one of the multi-threaded MPM's for Apache 2.  You'll 
save yourself a lot of hair pulling if you stick with the prefork mpm.  It 
bears saying that in the prefork mpm, each process does not share 
interpreter resources with the other processes.  This means each process 
will have it's own "pool" of database connections which may not bode well 
with your database server if you run a moderately heavy Apache load.


At 10:12 AM 2/2/2004 -0800, you wrote:
>I was wondering if there is any support for one-time initialization for 
>applications in mod-python - similar to the init() call of a servlet for 
>example. I would like to set up a database connection pool but I need to 
>do it only once when my app starts.
>If there is no support for initialization, what is the best way to set up 
>things that need to be set up only once per app in mod-python?
>Mod_python mailing list
>Mod_python at modpython.org

More information about the Mod_python mailing list