what does @tornado.web.asynchronous decorator mean?

linbo picture linbo · Jan 29, 2013 · Viewed 8.1k times · Source
  1. If code didn't use this decorator, is it non-blocking?
  2. Why this name is asynchronous, it means add decorator let code asynchronous?
  3. Why @tornado.gen always use with @tornado.web.asynchronous together?

Answer

Cole Maclean picture Cole Maclean · Jan 30, 2013

@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().

  1. Code not using this decorator can block, or not. Using the decorator doesn't change that in any way.

  2. As @Steve Peak said, you use the decorator for asynchronous requests, e.g. database retrieval.

  3. 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.