【发布时间】:2014-04-09 16:01:28
【问题描述】:
在document 中,如果方法也用@gen.coroutine 修饰,则@web.asynchronous 是不必要的。像这样
@web.asynchronous
@gen.coroutine
def get(self):
...
但是,在文档中,他们还解释说,如果您使用 @web.asynchronous,那么您应该调用 self.finish()。但是,在上述情况下(同时使用两个装饰器)连接完成,无需调用“self.finish()”
我想知道那里发生了什么。
在下面的情况下,它与上面的工作方式不同。
@web.asynchronous
def get(self):
self.test()
@gen.coroutine
def test(self):
httpClient = AsyncHttpClient()
val = yield httpClient.fetch("http://www.google.com")
print test
#self.finish()
如果没有调用“self.finish()”,则连接不会关闭。
有人能解释一下吗?
【问题讨论】:
标签: asynchronous tornado