def ping_listener(dbapi_conn, connection_rec, connection_proxy):
 try:
  dbapi_conn.cursor().execute('select 1')
 except dbapi_conn.OperationalError as ex:
  if (ex.args[0] in (2006, 2013, 2014, 2045, 2055)):
   msg = ('Got mysql server has gone away: %s' % ex)
   LOG.warn(msg)
   raise sqlalchemy.exc.DisconnectionError(msg)
  else:
   raise

def ping_listener ( dbapi_conn , connection_rec , connection_proxy ) : try : dbapi_conn . cursor ( ) . execute ( 'select 1' ) except dbapi_conn . OperationalError as ex : if ( ex . args [ 0 ] in ( 2006 , 2013 , 2014 , 2045 , 2055 ) ) : msg = ( 'Got mysql server has gone away: %s' % ex ) LOG . warn ( msg ) raise sqlalchemy . exc . DisconnectionError ( msg ) else : raise
ensures that mysql connections checked out of the pool are alive .