[mod_python] having modpython make a data base connection

David Bear David.Bear at asu.edu
Tue Jun 12 23:01:41 EDT 2007

On Wed, Jun 13, 2007 at 11:58:06AM +1000, Graham Dumpleton wrote:
> For starters, if you haven't read:
>  http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreterModel
> do so.

If I structure the program to exist in a single file, make my db
connections from there, does this imply that I could have 'multiple'
connections made to the data base? 

I am using the worker mode of apache on linux. This means that I do
have multiple child apaches and threads in each. So, I'm not sure if I
have 5 children and 2 thread per child that would imply 10 connections
to the data base?

> Second, be very careful about putting database connection objects in
> modules which are candidates for reloading. For stuff about how to
> deal with this if you want to do that, read documentation for
> import_module() in:

I don't know why a module would be reloaded. I'm still thinking in
terms of the cgi model where the script runs, connection made to db,
data is updated, connection closed, script dies, done.

Under what conditions would a module be reloaded? And if I use the
handler mode (no publisher or psp) and the data base connection is
made in the handler function, does that imply the connection is made
when apache is started (and the script is run for the first time) and
lives untill apache dies?

>  http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html
> I'll let others argue the merits of database connection pooling versus
> a connection per request as not an area I have direct experience with.

As they say, I'm against premature optimization -- I don't know enough
to care at this point. I just want to run in 'safest way', that means
the most predictable.

> Graham
> On 13/06/07, David Bear <David.Bear at asu.edu> wrote:
> >I don't want to start a flame ware here, but I'm starting to develop
> >and application that will connect to a postgresql server.
> >
> >I realize there are probably a dozen things I should know about
> >modpython before I begin.
> >
> >I will be use the standard python handler. I won't be using publisher
> >or psp (at least I think).
> >
> >I am afraid of issues like having modpython make a db connection
> >object that is not shared properly --. The more terrifying question is
> >what should be be asking.
> >
> >I wonder if someone has develop a top ten rules of thumb when using
> >modpython with sql data base connections?
> >
> >
> >--
> >David Bear
> >phone:  602-496-0424
> >fax:    602-496-0955
> >College of Public Programs/ASU
> >University Center Rm 622
> >411 N Central
> >Phoenix, AZ 85007-0685
> > "Beware the IP portfolio, everyone will be suspect of trespassing"
> >_______________________________________________
> >Mod_python mailing list
> >Mod_python at modpython.org
> >http://mailman.modpython.org/mailman/listinfo/mod_python
> >

David Bear
phone: 	602-496-0424
fax: 	602-496-0955
College of Public Programs/ASU
University Center Rm 622
411 N Central
Phoenix, AZ 85007-0685
 "Beware the IP portfolio, everyone will be suspect of trespassing"

More information about the Mod_python mailing list