Skip to content

Commit

Permalink
Merge pull request #205 from xBeAsTx/set_timeout_config
Browse files Browse the repository at this point in the history
allow change SYNC_REQUEST_TIMEOUT from config
  • Loading branch information
coldfix committed May 29, 2017
2 parents 64fc145 + 547e4af commit eb3c7b8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions rpyc/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class PingError(Exception):
credentials = None,
endpoints = None,
logger = None,
sync_request_timeout = 30,
)
"""
The default configuration dictionary of the protocol. You can override these parameters
Expand Down Expand Up @@ -112,6 +113,8 @@ class PingError(Exception):
remote one (``getpeername``). This is set by the server
upon accepting a connection; client side connections
do no have this configuration option set.
``sync_request_timeout`` ``30`` Default timeout for waiting results
======================================= ================ =====================================================
"""

Expand All @@ -130,8 +133,6 @@ class Connection(object):
need to call :func:`_init_service` manually later
"""

SYNC_REQUEST_TIMEOUT = 30

def __init__(self, service, channel, config = {}, _lazy = False):
self._closed = True
self._config = DEFAULT_CONFIG.copy()
Expand Down Expand Up @@ -460,9 +461,10 @@ def sync_request(self, handler, *args):
seq = self._get_seq_id()
self._send_request(seq, handler, args)
start_time = time.time()
timeout = self._config["sync_request_timeout"]

while seq not in self._sync_replies:
remaining_time = self.SYNC_REQUEST_TIMEOUT - (time.time() - start_time)
remaining_time = timeout - (time.time() - start_time)
if remaining_time < 0:
raise socket.timeout

Expand Down

0 comments on commit eb3c7b8

Please sign in to comment.