Pregunta

Estoy depurando de los errores 'El servidor MySQL Server ha desaparecido'.Hay una solución propuesta, que más o menos funciona:

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)

TOMADO DE AQUÍ: http://www.gelens.org/2009/09/13/Twisted-ConnectionPool-Revisited /

Sin embargo, la excepción no se captura solo en nuestro reconectingConnectionPool, sino también en _Runinteracción también.Y desencadena log.err, que (aparentemente) hace dos cosas:

  • Imprimir el error, aunque nuestra aplicación funciona bien
  • Lo que es peor, hace que la prueba falle, por lo que las pruebas fallan.No estoy realmente seguro de que este es un problema log.err, pero no obstante, sucede.

Podría hackear Adbapi, pero eso probablemente no sea la mejor idea.¿Hay alguna forma mejor para manejar esto?

¿Fue útil?

Solución

¿Está pidiendo cómo hacer un pase de prueba de unidad incluso si se registra un error?Pruebe FlushloggedErrors .Si está preguntando algo más, por favor aclare.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top