@tornado.web.asynchronous 装饰器是什么意思? [英] what does @tornado.web.asynchronous decorator mean?

查看:32
本文介绍了@tornado.web.asynchronous 装饰器是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 如果代码没有使用这个装饰器,它是非阻塞的吗?
  2. 为什么这个名字是异步的,意思是添加装饰器让代码异步?
  3. 为什么@tornado.gen 总是与@tornado.web.asynchronous 一起使用?

推荐答案

@tornado.web.asynchronous 防止 RequestHandler 自动调用 self.finish().就是这样;这只是意味着 Tornado 将保持连接打开,直到您手动调用 self.finish().

  1. 不使用这个装饰器的代码可以阻塞,也可以不阻塞.使用装饰器不会以任何方式改变这一点.

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

正如@Steve Peak 所说,您将装饰器用于异步请求,例如数据库检索.

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

为 Tornado 3.1+ 更新:如果你使用 @gen.coroutine,你也不需要使用 @asynchronous.我相信,旧的 @gen.engine 接口仍然需要 @asynchronous.

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.

这篇关于@tornado.web.asynchronous 装饰器是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆