執(zhí)行單個任務(wù),超過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
上面是說可以通過設(shè)置設(shè)置到期時間來修改。沒找到怎么通過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")
- 然后發(fā)現(xiàn)調(diào)了
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, 終于被我發(fā)現(xiàn)了在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對象的默認(rèn)超時是30s
解決方案
客戶端連接的時候在config里添加超時時間
client = rpyc.connect("xxx.xxx.xxx", 11111, config={'sync_request_timeout': 120})