clients.py 文件源码

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

项目:marathon-acme 作者: praekeltfoundation 项目源码 文件源码
def get_events(self, callbacks):
        """
        Attach to Marathon's event stream using Server-Sent Events (SSE).

        :param callbacks:
            A dict mapping event types to functions that handle the event data
        """
        d = self.request('GET', path='/v2/events', unbuffered=True, headers={
            'Accept': 'text/event-stream',
            'Cache-Control': 'no-store'
        })

        def handler(event, data):
            callback = callbacks.get(event)
            # Deserialize JSON if a callback is present
            if callback is not None:
                callback(json.loads(data))

        return d.addCallback(
            sse_content, handler, reactor=self._reactor, **self._sse_kwargs)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号