rpyc遇到的坑

執(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})
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc閱讀 2,995評論 0 0
  • 5/15/2017 7:06:35 PM 縱觀各大組件,配置文件占據(jù)極其重要的地位。可配置化也是當(dāng)下開發(fā)的一流行趨...
    愛做夢的胖子閱讀 4,536評論 0 8
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,858評論 0 10
  • Redis 配置文件示例 注意:想要讀取配置文件,Redis的第一個參數(shù)必須是文件的路徑 ./redis-serv...
    起個名忒難閱讀 1,359評論 0 1
  • 你最愛吃的食物是什么? 你最愛喝的又是什么? 你最愛的玩具和游戲是什么? 你最大的興趣愛好是什么? 你最愛的書是哪...
    是李恩爽呀閱讀 351評論 2 3

友情鏈接更多精彩內(nèi)容