On Dec 27, 2012, at 6:28 PM, Diego Woitasen wrote: > Hi, > I know that this was discussed several times in the past but I can't solve > the problem with the tip that I read in this list. Every morning my > application dies with the msg "MySQL has gone away". My app has different > modules (which are process) and this errors appears in the simplest one and > in the complex one too. There is no activity usually at night, specially in > one of the modules that has the issue more frequently. > > This lines setup the session: > > engine = create_engine(mysql_uri, pool_recycle=config.db_pool_recycle) # > Configure in 300 seconds right now. > DBSession = scoped_session(sessionmaker(autocommit=False, > autoflush=False, > bind=engine)) > > THe simplest module only do this with the DB: > > try: > delivery = db.DBSession.query(db.Delivery).\ > filter(db.Delivery.id == delivery_cmsg.delivery_id).one() > except NoResultFound: > print 'WARN: invalid delivery ID: ' + int(delivery_cmsg.delivery_id) > return > finally: > db.DBSession.commit() > > print delivery.name, delivery.start, delivery.status > > And it has the issue every morning. > > I'm using SA 0.7.9 and MySQLdb 1.2.4c1. > > Is there a checklist of things to check that could cause this problem?
so you've got pool_recycle, which will make sure the connection is refreshed when checked out from the pool. The other part is to make sure that when the app is idle, you have actually checked all connections back in. So this means every Session has been committed, rolled back, or closed, every Connection closed, every ResultProxy you might have gotten from executing a statement is fully exhausted of its rows and/or closed, and if you happen to be using the very old "thread local engine" system (which I don't recommend) you'd also have committed/rolled back any transaction there. -- 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 sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.