Twisted adbapi errors and log.err
Question: I'm debugging the 'MySQL server has gone away' errors. There is a proposed
solution, which more or less works:

    
    
    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)
    

Taken from here: <http://www.gelens.org/2009/09/13/twisted-connectionpool-
revisited/>

However, the exception gets caught no only in our ReconnectingConnectionPool,
but in _runInteraction itself too. And it triggers log.err, which (apparently)
does two things:

  * print the error - although our application works fine
  * what's worse, it makes trial fail, so the tests fail. I'm not really sure this is log.err problem, but it happens nonetheless.

I could hack adbapi, but that's probably not the best idea. Are there any
better ways to handle this?


Answer: Are you asking how to make a unit test pass even if an error is logged? Try
[flushLoggedErrors](http://twistedmatrix.com/documents/current/api/twisted.trial.unittest.TestCase.html#flushLoggedErrors).
If you're asking something else, please clarify.

