Twisted,MySQLdb和(2006年,"MySQL服务器已消失")使用Twisted adbapi [英] Twisted, MySQLdb and (2006, 'MySQL server has gone away') using Twisted adbapi

查看:168
本文介绍了Twisted,MySQLdb和(2006年,"MySQL服务器已消失")使用Twisted adbapi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在扭曲状态中,我是一个永久性事件循环,始终为寻找新查询而运行它轮询一个SQS队列,并且在两次查询之间的时间足够长以至于超时,这是我在获得新查询时遇到的错误查询到达...

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服务器具有 消失了")

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

这是我的联系

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'

问题在于它似乎不能很好地工作.因此..如果出现206错误,请尝试重新连接并再次执行查询.解决此问题的最佳实践是什么?

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?

谢谢

推荐答案

我没有使用 adbapi 的经验,但是

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)

这篇关于Twisted,MySQLdb和(2006年,"MySQL服务器已消失")使用Twisted adbapi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆