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