执行单个任务,超过30s自动中断
....
raise AsyncResultTimeout("result expired")
TimeoutError: result expired
首先看了下官方文档 https://rpyc.readthedocs.io/en/latest/tutorial/tut5.html
set_expiry(seconds) - sets the expiry time of the AsyncResult. By default, no expiry time is set
上面是说可以通过设置设置到期时间来修改。没找到怎么通过client获取AsyncResult对象的入口。无奈去分析了一下rypc源码:
- 先找到报错位置:
def wait(self):
"""Waits for the result to arrive. If the AsyncResult object has an
expiry set, and the result did not arrive within that timeout,
an :class:`AsyncResultTimeout` exception is raised"""
while not self._is_ready and not self._ttl.expired():
self._conn.serve(self._ttl)
if not self._is_ready:
raise AsyncResultTimeout("result expired")
- 然后发现调了
self._ttl.expired()
, 找到set_expiry位置
def set_expiry(self, timeout):
"""Sets the expiry time (in seconds, relative to now) or ``None`` for
unlimited time
:param timeout: the expiry time in seconds or ``None``
"""
self._ttl = Timeout(timeout)
- 全局搜索
timeout
, 终于被我发现了在protocol.py文件里
def sync_request(self, handler, *args):
"""Sends a synchronous request (waits for the reply to arrive)
:raises: any exception that the requets may be generated
:returns: the result of the request
"""
timeout = self._config["sync_request_timeout"]
return self.async_request(handler, *args, timeout=timeout).value
DEFAULT_CONFIG = dict(
...
sync_request_timeout = 30,
)
原因是AsyncResult对象的默认超时是30s
解决方案
客户端连接的时候在config里添加超时时间
client = rpyc.connect("xxx.xxx.xxx", 11111, config={'sync_request_timeout': 120})
网友评论