diff --git a/sjrpc/core/rpcconnection.py b/sjrpc/core/rpcconnection.py index d1e28fda8eed74e179133d0beab2f12bf10c44e5..de1d35c163381dbe2a31f2fe3cc9ad83b72768ec 100644 --- a/sjrpc/core/rpcconnection.py +++ b/sjrpc/core/rpcconnection.py @@ -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. @@ -226,6 +226,12 @@ class RpcConnection(object): seconds before to raise an :exc:`CallTimeout` exception if the peer 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: