It would be more "traditional" Webware to put the connect() into
SitePage.awake() and put the disconnect() into SitePage.sleep().  But your
method is fine.  Actually, it gives you better control, because you can
write it like this:

        def respond(self, trans):
                connected = []
                try:
                        for store in self._stores:
                                store.connect()
                                connected.append(store)
                        Page.respond(self, trans)
                finally:
                        for store in connected:
                                store.disconnect()

In case of exceptions, this will disconnect the stores that were connected.

As for performance, seems like it'll have some small impact, but probably
not enough to slow things down noticeably.  Since you're using DBPool, it's
not supposed to actually connect and disconnect every time so you should be
OK.

- Geoff

> -----Original Message-----
> From: Costas Malamas [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 21, 2002 12:46 PM
> To: Geoffrey Talvola; [EMAIL PROTECTED]
> Subject: RE: [Webware-discuss] A recipe for DbPool (maybe)
> 
> 
> 
> Yes, of course, I missed a step in my description: the Store classes 
> implement the object relational modeling (so UserStore will 
> retrieve User 
> objects from MySQL, for example).  In my case, Store has a self._conn 
> Connection member, which in the example below is initialized 
> as a connection 
> to a DBPool (because of the passing of the threaded switch in the 
> constructor).  Store.connect() and Store.disconnect() then simply 
> (dis)connect from the DBPool.
> 
> My concern here is whether or not wrapping the 
> connect/disconnect calls 
> around Page.respond() has any penalty on WK performance.
> 
> Thanks,
> 
> C.
> 
> 
> 
> >From: Geoffrey Talvola <[EMAIL PROTECTED]>
> >To: 'Costas Malamas' <[EMAIL PROTECTED]>, 
> >[EMAIL PROTECTED]
> >Subject: RE: [Webware-discuss] A recipe for DbPool (maybe)
> >Date: Wed, 21 Aug 2002 12:15:50 -0400
> >
> >I'm confused.  You're calling this a recipe for DbPool, but 
> I don't see any
> >usage of DbPool in your sample code below...
> >
> >What exactly does the "UserStore" do?  Is DbPool wrapped 
> into it somehow?
> >
> >- Geoff
> >
> > > -----Original Message-----
> > > From: Costas Malamas [mailto:[EMAIL PROTECTED]]
> > > Sent: Wednesday, August 21, 2002 6:51 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: [Webware-discuss] A recipe for DbPool (maybe)
> > >
> > >
> > >
> > > If y'all remember, I have had issues with WK crashing without
> > > a traceback.
> > > Much research later, my suspicions centered on MySQL for
> > > Python: basically,
> > > I figured that since I was not using a threadsafe DB link to
> > > WK, at some
> > > point MySQL was killing the connection to WK, which 
> brought WK down,
> > > probably via the mysqldb module.
> > >
> > > The only real way to verify this, was to switch to DBPool and
> > > see if that
> > > fixed my stability issues.  The problems there were that a)
> > > my ORM code is
> > > used by other non-WK python code that is not threaded, and b)
> > > that I already
> > > have kLOCs of code in place (check it out: http://memigo.com/).
> > >
> > > So, I came up with a solution that maybe a nice recipe for
> > > using DBPool; or
> > > it maybe brain-dead, and that's why I wanna run it by y'all
> > > (I will say
> > > though that it has fixed my stability problems for good).
> > >
> > > My ORM classes all inherit from a class called Store. I added
> > > an optional
> > > switch to Store, threaded, and a connect() and disconnect()
> > > method.  Now, in
> > > the constructor of my WK Page servlets, I changed calls like this:
> > >    self.userstore = UserStore()
> > >
> > > to this:
> > >    self.userstore = self.addStore(UserStore)
> > >
> > > (you will notice that is a simple regex job).  Where:
> > >
> > > class SitePage(Page):
> > >    ...
> > >
> > >    def addStore(storeClass):
> > >       storeObj = storeClass(threaded=1)
> > >       self._stores.append(storeObj)
> > >       return storeObj
> > >
> > >    def respond(self, trans):
> > >       for store in self._stores:
> > >          store.connect()
> > >       Page.respond(self, trans)
> > >       for store in self._stores:
> > >          store.disconnect()
> > >
> > > So, far, crashes have gone away, and the whole migration took
> > > about 1-2
> > > hours of running greps and seds and verifying the results.
> > > What do y'all
> > > think?  Is this a valid approach or can it be done faster/better?
> > >
> > > Thanks,
> > >
> > > Costas
> > >
> > >
> > >
> > >
> > >
> > > _________________________________________________________________
> > > Chat with friends online, try MSN Messenger: 
> http://messenger.msn.com
> > >
> > >
> > >
> > > -------------------------------------------------------
> > > This sf.net email is sponsored by: OSDN - Tired of that same old
> > > cell phone?  Get a new here for FREE!
> > > https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
> > > _______________________________________________
> > > Webware-discuss mailing list
> > > [EMAIL PROTECTED]
> > > https://lists.sourceforge.net/lists/listinfo/webware-discuss
> > >
> 
> 
> 
> 
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
> 


-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to