@tornado.web.asynchronous
prevents the the RequestHandler
from automatically calling self.finish()
. That's it; it just means Tornado will keep the connection open until you manually call self.finish()
.
Code not using this decorator can block, or not. Using the decorator doesn't change that in any way.
As @Steve Peak said, you use the decorator for asynchronous requests, eg database retrieval.
Updated for Tornado 3.1+: If you use @gen.coroutine
, you don't need to use @asynchronous
as well. The older @gen.engine
interface still requires @asynchronous
, I believe.
Answered here: asynchronous vs non-blocking
Think of it like this. When you need to make a request to say a database or another url to retrieve data you do not want to block your tornado IO. So the @tornado.web.asynchronous
will allow the IO to handle other requests while it waits for the content to load (ex. database or url).
They are simular. You most likely will use @tornado.web.asynchronous
.
@tornado.web.asynchronous
本质上只是一个标记,你放在一个像get()
或post()
这样的处理程序方法上,告诉框架它不应该在方法返回时自动调用finish()
,因为它包含的代码是将要设置finish()
以便稍后调用。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.