0

When should we add this decorator ? what is the benefits of adding this decorator ? what's the differences between with tornado.gen?

I will be very appreciate if anyone could give me some details

liuzhidong
  • 538
  • 3
  • 18
  • possible duplicate of [what does @tornado.web.asynchronous decorator mean?](http://stackoverflow.com/questions/14582415/what-does-tornado-web-asynchronous-decorator-mean) – bosnjak Dec 08 '14 at 14:30

1 Answers1

1

@asynchronous is a promise to call self.finish() instead of letting the request be finished automatically. This allows you to use asynchronous operations via callbacks.

@gen.coroutine (and @gen.engine, which is mostly obsolete) give the yield keyword special meaning, allowing you to use asynchronous operations via Futures and Tasks.

Use @gen.coroutine when you use the yield keyword, and @asynchronous when you use callbacks. In Tornado 3.0 it was sometimes necessary to use both together (and put @asynchronous first), but since Tornado 3.1 there is no reason to do so and you should only use one or the other.

Ben Darnell
  • 21,844
  • 3
  • 29
  • 50