龙卷风中流服务器发送的事件

时间:2019-08-20 12:37:12

标签: python python-3.x asynchronous tornado server-sent-events

我正在尝试在运行于Python 3.5.2上的tornado 6.0.3中实现服务器发送事件(SSE)。我的请求处理程序基本上如下:

class SSEHandler(tornado.web.RequestHandler):
    async def get(self):
        from tornado.gen import sleep
        self.set_header('content-type', 'text/event-stream')
        self.set_header('cache-control', 'no-cache')
        try:
            for i in range(60):
                await sleep(1)
                self.write('data: Test data\n\n')
                await self.flush()
        except StreamClosedError:
            pass

不幸的是,客户端似乎仅在使用了for循环之后才收到响应。我希望处理程序在RequestHandler.flush()上传输每个消息。我想念什么?

0 个答案:

没有答案
相关问题