def set_up(self, u, engine):
        """Special setup for mysql engines"""
        # add the reconnecting PoolListener that will detect a
        # disconnected connection and automatically start a new
        # one.  This provides a measure of additional safety over
        # the pool_recycle parameter, and is useful when e.g., the
        # mysql server goes away
        def checkout_listener(dbapi_con, con_record, con_proxy):
            try:
                cursor = dbapi_con.cursor()
                cursor.execute("SELECT 1")
            except dbapi_con.OperationalError as ex:
                if self.is_disconnect(ex.args):
                    # sqlalchemy will re-create the connection
                    log.msg('connection will be removed')
                    raise sa.exc.DisconnectionError()
                log.msg('exception happened {}'.format(ex))
                raise

        # older versions of sqlalchemy require the listener to be specified
        # in the kwargs, in a class instance
        if sautils.sa_version() < (0, 7, 0):
            class ReconnectingListener:
                pass
            rcl = ReconnectingListener()
            rcl.checkout = checkout_listener
            engine.pool.add_listener(rcl)
        else:
            sa.event.listen(engine.pool, 'checkout', checkout_listener)
def set_up ( self , u , engine ) : def checkout_listener ( dbapi_con , con_record , con_proxy ) : try : cursor = dbapi_con . cursor ( ) cursor . execute ( "SELECT 1" ) except dbapi_con . OperationalError as ex : if self . is_disconnect ( ex . args ) : log . msg ( 'connection will be removed' ) raise sa . exc . DisconnectionError ( ) log . msg ( 'exception happened {}' . format ( ex ) ) raise if sautils . sa_version ( ) < ( 0 , 7 , 0 ) : class ReconnectingListener : pass rcl = ReconnectingListener ( ) rcl . checkout = checkout_listener engine . pool . add_listener ( rcl ) else : sa . event . listen ( engine . pool , 'checkout' , checkout_listener )
Special setup for mysql engines