執(zhí)行單個(gè)任務(wù)腋逆,超過(guò)30s自動(dòng)中斷
....
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
上面是說(shuō)可以通過(guò)設(shè)置設(shè)置到期時(shí)間來(lái)修改。沒(méi)找到怎么通過(guò)client獲取AsyncResult對(duì)象的入口吊输。無(wú)奈去分析了一下rypc源碼:
- 先找到報(bào)錯(cuò)位置:
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對(duì)象的默認(rèn)超時(shí)是30s
解決方案
客戶端連接的時(shí)候在config里添加超時(shí)時(shí)間
client = rpyc.connect("xxx.xxx.xxx", 11111, config={'sync_request_timeout': 120})