Domanda

Sono il debug del "MySQL Server è andato via gli errori.C'è una soluzione proposta, che più o meno funziona:

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)
.

Preso da qui: http://www.gelens.org/2009/09/13/13Twisted-ConnectionPool-rivisitato /

Tuttavia, l'eccezione viene catturata non solo nella nostra riconnectionConnectionPool, ma anche in _Runinterazione stessa.E trigger è log.err, che (apparentemente) fa due cose:

    .
  • Stampa l'errore - Sebbene la nostra applicazione funzioni fini
  • Cosa c'è di peggio, fa fallire la prova, quindi i test falliscono.Non sono proprio sicuro che questo sia il problema di Log.err, ma succede comunque.

Potrei incidere adbapi, ma probabilmente non è la migliore idea.Ci sono modi migliori per gestire questo?

È stato utile?

Soluzione

Stai chiedendo come effettuare un test dell'unità anche se è registrato un errore?Prova FlushloggedErrors .Se stai chiedendo qualcos'altro, per favore chiariscono.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top