问题描述
在扭曲状态中,我是一个永久性事件循环,始终为寻找新查询而运行它轮询一个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...
这是我的联系
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 的经验,但是 docs ,看起来很有希望.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!