I tried all you said. Here is my code:

engine = create_engine(db_url, 
pool_size=100,max_overflow=150,echo=engine_echo,pool_recycle=3600)

And, in the beginning, I googled a lot and add this:
def _ping_db():
    #session.execute('show variables')
    try:
        session.execute('select 1')
    except (InvalidRequestError,StatementError,OperationalError),e:
        dba_logger.log(30,'Exception when pinging db:%s' % str(e))
        session.rollback()

if pool_rec:
    # ping db, so that mysql won't goaway
    PeriodicCallback(_ping_db, pool_recycle_time * 1000).start()

But still hit the issue often, what's strange is, actually, the exception 
raises during many db operations..
That is, several db operations are successful, then, for the coming request 
just after that, suddenly, mysql gone away...


在 2014年3月19日星期三UTC+8上午7时54分21秒,Jameson Lee写道:
>
> Your connection to the database has been idle for too long and MySQL has 
> disconnected it.  You can mitigate it by having fake traffic that will use 
> the connection.  Increasing the timeout of MySQL.  Set SQLAlchemy to 
> recycle connections in the connection pool more aggressively (and make sure 
> that this value is below the MySQL timeout limit)
>
> I believe the default is 3600 or 7200 seconds for the above values.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to