【发布时间】:2014-12-13 05:24:13
【问题描述】:
您好,我在执行长轮询时遇到了 Tornado 框架的问题。
我的 requesthandler 的 post 方法用@asynchronous 和@gen.coroutine 装饰。当我让它挂起以调用回调以写回客户端时,连接立即关闭。我看到这与@gen.coroutine 的使用有关,当所有期货都产生时,它会自动调用self.finish()。
我需要这个装饰器,因为我使用的是 Mongo Motor。
下面是一个简短的例子:
@web.asynchronous
@gen.coroutine
def post(self):
#mongo Motor yielding code
notifications.register_callback(self.on_message)
Notifications 是一个全局对象,它保存一组回调,并在接收到来自外部的消息时调用它们。 谢谢
【问题讨论】:
标签: python tornado long-polling