Python pyramid SQLAlchemy, MySQL server gone

I have many posts about this issue. My understanding is that the application has a parameter that says how long to maintain idle database connections before dropping them and creating new ones. MySQL has a parameter that says how long to maintain idle connections. After the site is inactive, MySQL does not connect applications. But the application does not know this and is still trying to use an existing connection that fails. After the failure, the application drops the connection and creates a new one, and then this is normal.

I have wait_timeout set to 10 seconds on my local mysql server. I have pool_recycle set to 5 seconds on my locally running application. After 10 seconds of inactivity, I make a request and still get this error. Fulfilling another request later within 10 seconds then it is fine. Waiting more than 10 seconds, he again gives this error.

Any thoughts?

mysql> SELECT @@global.wait_timeout\G
*************************** 1. row ***************************
@@global.wait_timeout: 10
1 row in set (0.00 sec)

.

sqlalchemy.twelvemt.pool_recycle = 5

.

engine = engine_from_config(settings, 'sqlalchemy.twelvemt.')
DBSession.configure(bind=engine)

.

OperationalError: (OperationalError) (2006, 'MySQL server has gone away') 'SELECT beaker_cache.data \nFROM beaker_cache \nWHERE beaker_cache.namespace = %s' ('7cd57e290c294c499e232f98354a1f70',)

+4
source share
3 answers

It appears that the error you received is triggered by your Beaker connection, not your DBSession connection. The pool_recycle parameter must be set for each connection.

, Beaker x.ini, sqlalchemy session.sa.*, session.sa.pool_recycle = 5

. http://docs.pylonsproject.org/projects/pylons-webframework/en/v0.9.7/sessions.html#sa

+2

sqlalchemy.pool_recycle

mySQL

sqlalchemy.pool_recycle = 3600

MySQL server has gone away .

+2

, remove() . , :

def remove_session(request, response):
    request.dbsession.remove()

, :

def __init__(self, request):
    request.dbsession = DBSession
    request.add_response_callback(remove_session)

, SQLAlchemy , . .

0

All Articles