#NEWLINE# def borrow_connection( self , timeout ) : #NEWLINE# #INDENT# if self . is_shutdown : #NEWLINE# #INDENT# raise ConnectionException ( ( 'Pool for %s is shutdown' % ( self . host , ) ) , self . host ) #NEWLINE# #UNINDENT# conn = self . _connection #NEWLINE# if ( not conn ) : #NEWLINE# #INDENT# raise NoConnectionsAvailable ( ) #NEWLINE# #UNINDENT# start = time . time ( ) #NEWLINE# remaining = timeout #NEWLINE# while True : #NEWLINE# #INDENT# with conn . lock : #NEWLINE# #INDENT# if ( conn . in_flight <= conn . max_request_id ) : #NEWLINE# #INDENT# conn . in_flight += 1 #NEWLINE# return ( conn , conn . get_request_id ( ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( timeout is not None ) : #NEWLINE# #INDENT# remaining = ( ( timeout - time . time ( ) ) + start ) #NEWLINE# if ( remaining < 0 ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# with self . _stream_available_condition : #NEWLINE# #INDENT# self . _stream_available_condition . wait ( remaining ) #NEWLINE# #UNINDENT# #UNINDENT# raise NoConnectionsAvailable ( 'All request IDs are currently in use' )