Mysql 扭曲的adbapi错误和log.err

Mysql 扭曲的adbapi错误和log.err,mysql,twisted,trial,Mysql,Twisted,Trial,我正在调试“MySQL服务器已经消失”错误。有一个提议的解决方案,或多或少是可行的: from twisted.enterprise import adbapi from twisted.python import log import MySQLdb class ReconnectingConnectionPool(adbapi.ConnectionPool): """Reconnecting adbapi connection pool for MySQL. This c

我正在调试“MySQL服务器已经消失”错误。有一个提议的解决方案,或多或少是可行的:

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)
摘自这里:

然而,异常不仅在我们的重新连接连接池中被捕获,而且在运行交互本身中也被捕获。它触发log.err,它(显然)做两件事:

  • 打印错误-尽管我们的应用程序工作正常
  • 更糟糕的是,它使试验失败,所以测试失败。我不确定这是否是log.err问题,但还是会发生

我可以破解adbapi,但这可能不是最好的主意。有没有更好的方法来处理这个问题?

您是否在询问即使记录了错误,如何使单元测试通过?尝试如果您有其他问题,请澄清。

是的,这正是我需要的。非常感谢。如果它不在日志中写入任何内容,那就太好了,但我可以接受这个事实:-)