Commit 4a764643 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added timeout feature on (remote) call method.

parent 2daf7421
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ class RpcConnection(object):
        err = {'exception': error, 'message': message}
        self._send_response(msg_id, error=err)
    
    def call(self, method_name, *args, **kwargs):                                #TODO: timeout
    def call(self, method_name, *args, **kwargs):
        '''
        Make a new remote call on the peer.
        
@@ -227,6 +227,12 @@ class RpcConnection(object):
           didnt respond.
        '''

        if '_timeout' in kwargs:
            timeout = kwargs['_timeout']
            del kwargs['_timeout']
        else:
            timeout = None
        
        # Send the call to the peer:
        msg_id = self._send_call(method_name, *args, **kwargs)
        
@@ -235,7 +241,11 @@ class RpcConnection(object):
                               'event': threading.Event()}
        
        # Wait for the response:
        self._calls[msg_id]['event'].wait()
        self._calls[msg_id]['event'].wait(timeout)

        # Check if timeout occured:
        if not self._calls[msg_id]['event'].is_set():
            raise RpcError('TimeoutError', 'remote method timeout')
        
        # Check if error occured while execution:
        if self._calls[msg_id]['error'] is not None: