#NEWLINE# def _wait_for_conn( self , timeout ) : #NEWLINE# #INDENT# start = time . time ( ) #NEWLINE# remaining = timeout #NEWLINE# while ( remaining > 0 ) : #NEWLINE# #INDENT# self . _await_available_conn ( remaining ) #NEWLINE# if self . is_shutdown : #NEWLINE# #INDENT# raise ConnectionException ( 'Pool is shutdown' ) #NEWLINE# #UNINDENT# conns = self . _connections #NEWLINE# if conns : #NEWLINE# #INDENT# least_busy = min ( conns , key = ( lambda c : c . in_flight ) ) #NEWLINE# with least_busy . lock : #NEWLINE# #INDENT# if ( least_busy . in_flight < least_busy . max_request_id ) : #NEWLINE# #INDENT# least_busy . in_flight += 1 #NEWLINE# return ( least_busy , least_busy . get_request_id ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# remaining = ( timeout - ( time . time ( ) - start ) ) #NEWLINE# #UNINDENT# raise NoConnectionsAvailable ( )