0
我正在調試'MySQL服務器已經消失'的錯誤。有一個建議的解決方案,這或多或少的作品:扭曲的adbapi錯誤和log.err
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/
然而,除了得不到只有在我們ReconnectingConnectionPool抓住了,但在_runInteraction本身了。它觸發LOG.ERR,它(顯然)做了兩兩件事:
- 打印錯誤 - 儘管我們的應用程序工作正常
- 更糟糕的是,它使試驗失敗,所以測試失敗。我不確定這是否是log.err問題,但它仍然會發生。
我可以破解adbapi,但這可能不是最好的主意。有沒有更好的方法來處理這個問題?
是的,這正是我所需要的。謝謝! 如果它沒有在日誌中寫任何東西,那會很好,但我可以忍受這個:-) – 2012-07-30 07:29:07