client.py 文件源码

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

项目:twistes 作者: avihad 项目源码 文件源码
def close(self):
        """
        close all http connections.
        returns a deferred that fires once they're all closed.
        """

        def validate_client(client):
            """
            Validate that the connection is for the current client
            :param client:
            :return:
            """
            host, port = client.addr
            parsed_url = urlparse(self._hostname)
            return host == parsed_url.hostname and port == parsed_url.port

        # read https://github.com/twisted/treq/issues/86
        # to understand the following...
        def _check_fds(_):
            fds = set(reactor.getReaders() + reactor.getReaders())
            if not [fd for fd in fds if isinstance(fd, Client) and validate_client(fd)]:
                return

            return deferLater(reactor, 0, _check_fds, None)

        pool = self._async_http_client_params["pool"]
        return pool.closeCachedConnections().addBoth(_check_fds)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号