Question

Je débogage du "Server MySQL est parti" des erreurs.Il y a une solution proposée, qui fonctionne plus ou moins:

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)

pris d'ici: http://www.gelens.org/2009/09/13/Twisted-ConnectionPool-Revisited /

Cependant, l'exception ne se fait rien que dans notre reconnecteConnectivePool, mais en _RuninterAction elle-même aussi.Et il déclenche log.err, lequel (apparemment) fait deux choses:

  • Imprimez l'erreur - bien que notre application fonctionne bien
  • Ce qui est pire, il échoue d'essai, de sorte que les tests échouent.Je ne suis pas vraiment sûr que c'est un problème log.err, mais cela arrive néanmoins.

Je pourrais pirater Adbapi, mais ce n'est probablement pas la meilleure idée.Y a-t-il de meilleurs moyens de gérer cela?

Était-ce utile?

La solution

Vous demandez comment effectuer un test d'unité même si une erreur est enregistrée?Essayez flushloggedrors .Si vous demandez autre chose, veuillez clarifier.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top