client.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:tornetcd 作者: mqingyn 项目源码 文件源码
def search_machine(self, callback=None):
        uri = self._base_url + self.version_prefix + '/machines'
        req = HTTPRequest(uri, self._MGET, request_timeout=self.read_timeout,
                          follow_redirects=self.allow_redirect, )
        response_future = self.http.fetch(req, callback=lambda result: result)

        def _callback(fut):
            exc = fut.exc_info()
            if exc:
                if not isinstance(exc[1], etcdexcept.EtcdException):
                    # We can't get the list of machines, if one server is in the
                    # machines cache, try on it
                    _log.error("Failed to get list of machines from %s%s: %r and retry it.",
                               uri, self.version_prefix, exc)
                    if self._machines_cache:
                        self._base_url = self._machines_cache.pop(0)
                        _log.debug("Retrying on %s", self._base_url)
                        # Call myself
                        self.ioloop.add_future(self.search_machine(), _callback)
                        return
                    else:
                        raise etcdexcept.EtcdException("Could not get the list of servers, "
                                                       "maybe you provided the wrong "
                                                       "host(s) to connect to?")
            else:
                response = fut.result()
                machines = [
                    node.strip() for node in
                    self._handle_server_response(response).body.decode('utf-8').split(',')
                    ]
                _log.debug("Retrieved list of machines: %s", machines)
                self._machines_cache = machines
                if self._base_url not in self._machines_cache:
                    self._base_url = self._choice_machine()
            callback(fut.result())

        self.ioloop.add_future(response_future, _callback)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号