题
我正在调试'mysql server已消失'错误。有一个提出的解决方案,或多或少的作品:
from twisted.enterprise import adbapi
from twisted.python import log
import MySQLdb
class ReconnectingConnectionPool(adbapi.ConnectionPool):
"""Reconnecting adbapi connection pool for MySQL.
This class improves on the solution posted at
http://www.gelens.org/2008/09/12/reinitializing-twisted-connectionpool/
by checking exceptions by error code and only disconnecting the current
connection instead of all of them.
Also see:
http://twistedmatrix.com/pipermail/twisted-python/2009-July/020007.html
"""
def _runInteraction(self, interaction, *args, **kw):
try:
return adbapi.ConnectionPool._runInteraction(self, interaction, *args, **kw)
except MySQLdb.OperationalError, e:
if e[0] not in (2006, 2013):
raise
log.msg("RCP: got error %s, retrying operation" %(e))
conn = self.connections.get(self.threadID())
self.disconnect(conn)
# try the interaction again
return adbapi.ConnectionPool._runInteraction(self, interaction, *args, **kw)
.
从这里拍摄: http://www.gelens.org/2009/09/13/Twisted-ConnectionPool-Revisited /
但是,异常只会在我们的重新连接到occentingConectionPool中捕获,但在_Runinteraction本身也是如此。它触发了log.err,哪个(显然)是两件事:- 打印错误 - 虽然我们的应用程序工作正常
- 更糟糕的是,它使试用失败,所以测试失败了。我真的不确定这是log.err问题,但它仍然发生。
我可以破解adbapi,但这可能不是最好的想法。有没有更好的方法来处理这个?
解决方案
您是否询问如何进行单位测试通过,即使错误被记录?尝试 flushloggederrors 。如果你问别的东西,请澄清。
不隶属于 StackOverflow