On 8/30/07, Moshe C. <[EMAIL PROTECTED]> wrote: > > I was hoping there was something more elegant than just trying and > catching a possible exception. > The motivation is just simpler and more readable code like > if not connection.is_valid(): > get another one
The issue is that in a packet-based network, there's no way to tell if the connection is alive without generating some traffic and seeing if it succeeds. SQLAlchemy could, and perhaps should, encapsulate this in a method but it doesn't. I've also argued that SQLAlchemy should seamlessly retry a query if it finds a connection dead, but MikeB says this is not safe in a transaction. The SQLAlchemy Way is to set the 'pool_recycle' engine option to a value lower than the database's timeout. MySQL seems to be the main culprit, and it has a default timeout of 8 hours or so, so setting pool_recycle=3600 (one hour) is well within the limit. -- Mike Orr <[EMAIL PROTECTED]> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---