Twisted Adbapiエラーとlog.err.
質問
「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 /
しかし、例外は、ReconnectionConnectionPoolだけではなく、_runInteraction自体でも捉えられます。そしてそれはlog.errを起動します。これは(明らかに)2つのことをします。
- エラーを印刷する - 私たちのアプリケーションはうまくいきますが
- 何が悪いのか、それは試行を失敗させるので、テストは失敗します。これがlog.err問題であることは本当にわかりませんが、それにもかかわらず起こります。
私はAdbapiをハックすることができましたが、それはおそらく最高のアイデアではありません。これを処理するより良い方法はありますか?
解決
エラーが記録されていても、ユニットテストパスの作成方法を尋ねていますか? flushloggederrors 。他のものを求めている場合は、明確にしてください。
所属していません StackOverflow