#NEWLINE# def run( self ) : #NEWLINE# #INDENT# self . _shutdown_event . wait ( self . _interval ) #NEWLINE# while ( not self . _shutdown_event . is_set ( ) ) : #NEWLINE# #INDENT# start_time = time . time ( ) #NEWLINE# futures = [ ] #NEWLINE# failed_connections = [ ] #NEWLINE# try : #NEWLINE# #INDENT# for ( connections , owner ) in [ ( o . get_connections ( ) , o ) for o in self . _get_connection_holders ( ) ] : #NEWLINE# #INDENT# for connection in connections : #NEWLINE# #INDENT# self . _raise_if_stopped ( ) #NEWLINE# if ( not ( connection . is_defunct or connection . is_closed ) ) : #NEWLINE# #INDENT# if connection . is_idle : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# futures . append ( HeartbeatFuture ( connection , owner ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# log . warning ( 'Failed sending heartbeat message on connection (%s) to %s' , id ( connection ) , connection . host ) #NEWLINE# failed_connections . append ( ( connection , owner , e ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# connection . reset_idle ( ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# owner . return_connection ( connection ) #NEWLINE# #UNINDENT# #UNINDENT# self . _raise_if_stopped ( ) #NEWLINE# #UNINDENT# for f in futures : #NEWLINE# #INDENT# self . _raise_if_stopped ( ) #NEWLINE# connection = f . connection #NEWLINE# try : #NEWLINE# #INDENT# f . wait ( self . _interval ) #NEWLINE# with connection . lock : #NEWLINE# #INDENT# connection . in_flight -= 1 #NEWLINE# #UNINDENT# connection . reset_idle ( ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# log . warning ( 'Heartbeat failed for connection (%s) to %s' , id ( connection ) , connection . host ) #NEWLINE# failed_connections . append ( ( f . connection , f . owner , e ) ) #NEWLINE# #UNINDENT# #UNINDENT# for ( connection , owner , exc ) in failed_connections : #NEWLINE# #INDENT# self . _raise_if_stopped ( ) #NEWLINE# connection . defunct ( exc ) #NEWLINE# owner . return_connection ( connection ) #NEWLINE# #UNINDENT# #UNINDENT# except self . ShutdownException : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# except Exception : #NEWLINE# #INDENT# log . error ( 'Failed connection heartbeat' , exc_info = True ) #NEWLINE# #UNINDENT# elapsed = ( time . time ( ) - start_time ) #NEWLINE# self . _shutdown_event . wait ( max ( ( self . _interval - elapsed ) , 0.01 ) )