client.py 文件源码

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

项目:Sentry 作者: NetEaseGame 项目源码 文件源码
def urlopen(self, method, path, **kwargs):
        """
        Make a request using the next server according to the connection
        strategy, and retries up to max_retries attempts. Ultimately,
        if the request still failed, we reraise the HTTPError from
        urllib3. If at the start of the request, there are no known
        available hosts, we revive all dead connections and forcefully
        attempt to reconnect.
        """
        # If we're trying to initiate a new connection, and
        # all connections are already dead, then we should flail
        # and attempt to connect to one of them
        if len(self.connections) == 0:
            self.force_revive()

        # We don't need strict host checking since our client is enforcing
        # the correct behavior anyways
        kwargs.setdefault('assert_same_host', False)

        try:
            for _ in xrange(self.max_retries):
                conn = self.strategy.next(self.connections)
                try:
                    return conn.urlopen(method, path, **kwargs)
                except HTTPError:
                    self.mark_dead(conn)

                    if len(self.connections) == 0:
                        raise
        finally:
            self.cleanup_dead()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号