开发者

Twisted, MySQLdb and (2006, 'MySQL server has gone away') using Twisted adbapi

开发者 https://www.devze.com 2023-04-10 12:55 出处:网络
开发者_StackOverflow中文版In twisted I am a perpetual event loop that is always lookig for a new query to runIt polls a SQS queue and are are times where time between queres is long enough to time out

开发者_StackOverflow中文版In twisted I am a perpetual event loop that is always lookig for a new query to run It polls a SQS queue and are are times where time between queres is long enough to time out and this is the error I get when a new query arrives...

MySQLdb _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')

here is my connection

self.pool = adbapi.ConnectionPool("MySQLdb", self.parms['host'], self.parms['username'], self.parms['password'], self.parms['database'])

Here is the logic I use to try and solve the problem.

try:
    d = self.pool.runQuery(query, ())
except:
    self.pool = adbapi.ConnectionPool("MySQLdb", self.parms['host'], self.parms['username'], self.parms['password'], self.parms['database']) 
    d = self.pool.runQuery(query, ())
    print 'Reconnecting'

Problem is that it does not seem to work very well. So..if a get a 206 error the try reconnection and execute the query again. What is best practice to solve this problem?

Thanks


I have no experience with adbapi, but cp_reconnect parameter, mentioned in docs, looks promising.

Thus your pool initialization will look something like:

self.pool = adbapi.ConnectionPool("MySQLdb", self.parms['host'], self.parms['username'], self.parms['password'], self.parms['database'], cp_reconnect=True)
0

精彩评论

暂无评论...
验证码 换一张
取 消