Re: Re: Reusing connections quixote 2

"Mike Orr" <[email protected]> Tue, 7 Nov 2006 11:45:21 -0800
Newsgroups gmane.comp.web.quixote.user
Message-ID <[email protected]>
On 11/7/06, Arturo FM <[email protected]> wrote:
> >The smart reconnect modules also have connection pooling.  It will
> >leave unused connections open and hand them back to the next routine
> >that asks for one.  SQLAlchemy has this and there's also a standalone
> >module I'm planning to try, although I can't find the link to it now.
> >SQLObject has the same feature but I'm not sure if you can use it
> >alone (without SQLObject's OO features).
> OK! I will find this module of SQLAlchemy. I think that I could write a class with methods for check if the connection is "alive". If the exception is thrown then try to reconnect.

The point is, you don't have to!  This is jumping into the middle of
the manual, but with SQLAlchemy you can set a lifetime on connections,
after which they will be closed and reopened.  You can set this to an
hour or two and forget about it.  See the pool_recycle=3600 argument.

http://www.sqlalchemy.org/docs/dbengine.myt#dbengine_options

I didn't find definitive confirmation that it will transparently
reopen a connection if a query fails, but you can look in the source
to see.  (It would be an exception catching.)  If it doesn't, the main
thing to remember is to restart the application whenever you restart
the database server.

-- 
Mike Orr <[email protected]>