Chuck,
 Thanks!
I never saw the atexit function, I'll add it to my application.  
I never worried about this too much because in a 
production setting it should not matter.

BTW - I have one issue w/ not closing the connections using PgSQL - 
when I use the oneShot.cgi I was opening about 25 connections each time and not 
closing them.
Postgres times them out and closes them, but I was runnning oneshot too fast for the 
db to keep 
up and I kept running out of connections on my test db server.  I fixed it by chaning 
the initial pool
size to 1 connection per pool rather then 5-10

Aleksandar,
  Use the DBPool - the .getConnection() returns an open connection just for that 
servlet.  
When you close the connection - conn.close()  The connection is automatically returned 
to the pool.  This takes care of the threading.

----- Original Message ----- 
From: "Aleksandar Kacanski" <[EMAIL PROTECTED]>
To: "Aaron Held" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, November 12, 2001 4:38 PM
Subject: Re: [Webware-discuss] approach to db connection pooling


> I read article (Message: 4217027) and implemented
> what Jay Love suggested.
> This was something down the line of implementing 
> Application.__init__() that sets up initial
> connection method, and servlets accessing it via
> Application object through self.application() and
>  awake() method.
> My connection to the DB is cached. In servlets I
> use awake() and do something like this:
> self.c = self.application().MyDBConn to get the
> pyPgSQL connection  object.
> 
> I have wrapper that manipulates stuff on pyPgSQL
> level that is used in both connection and
> manipulation of the data.
> 
> I think that as is I am passing object from the
> servlet to servlet.
> 
> I am still not sure on how to implement a proper
> closure of the DB connection, dough i have it
> implemented in the wrapper. I guess that  atexit
> as Chuck suggested could be implemented.
> I am not sure how above approach affects multi
> threading.
> Maybe someone could shed some light on this one?
> thanks for the response. I'll try your approach.
> 
> 
> 
> --- Aaron Held <[EMAIL PROTECTED]> wrote:
> > I had some similar issues,
> > 
> > A python module runs the first time its called
> > and then stays resident in the python
> > interpreter for the duration of the app.
> > So anywhere you have a module you can define a
> > new global variable.
> > 
> > Here is a snip of my configuration.py file that
> > gets imported by each servlet
> > 
> > datapool = DBPool(PgSQL, 1,
> > '192.168.0.10::comsci:user:pass')
> > clientpool={}
> > clientpool['metrony']=DBPool(PgSQL, 2,
> > '192.168.0.10::metrony:user:pass')
> > 
> > And then to use any connection I call it like:
> > 
> > from configuration import datapool,clientpool
> > 
> > #
> > #  This is a big ugly class to handle all of
> > the database interaction.
> > # It will get better
> > 
> > def summaryStats(user):
> >   summary={}
> >   conn=clientpool[user.company].getConnection()
> >   c=conn.cursor()
> >   c.execute("Select numrows from numrows")
> >   r=c.fetchone()
> >   summary['numrows'] = r.numrows
> >   return summary
> > 
> > So I create a dictionary of DB connections and
> > use the company name as the key.
> > 
> > Now if I could only close the connections
> > cleanly.......
> > 
> > -Aaron
> > 
> > ----- Original Message ----- 
> > From: "Aleksandar Kacanski"
> > <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Monday, November 12, 2001 11:57 AM
> > Subject: [Webware-discuss] approach to db
> > connection pooling
> > 
> > 
> > > Any new developments on the db connection
> > > pooling?
> > > I have been trying for couple of days
> > > (unsuccessfully) to make some sort of 
> > > session caching, attaching db object to the
> > > Application object or Cans approach.
> > > Does anyone has any examples of how this
> > might be
> > > implemented. I am interested in getting
> > several
> > > connections open at the startup of the App,
> > and
> > > passing the object to servlets.
> > > any suggestions?
> > > 
> > >
> >
> __________________________________________________
> > > Do You Yahoo!?
> > > Find a job, post your resume.
> > > http://careers.yahoo.com
> > > 
> > >
> > _______________________________________________
> > > Webware-discuss mailing list
> > > [EMAIL PROTECTED]
> > >
> >
> https://lists.sourceforge.net/lists/listinfo/webware-discuss
> > 
> > 
> 
> __________________________________________________
> Do You Yahoo!?
> Find a job, post your resume.
> http://careers.yahoo.com



_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to