AttributeError: module 'tornado.web' has no attribute 'asynchronous'解决方法

AttributeError: module ‘tornado.web’ has no attribute 'asynchronous’解决方法

在这里插入图片描述
今天看tornado异步时发现的错误,查了一下,原来tornado6以后就弃用了tornado.web.asynchronous这种写法了。
不需要加这种写法

在这里插入图片描述

class GenAsyncHandler(RequestHandler):
    @gen.coroutine
    def get(self):
        http_client = AsyncHTTPClient()
        response = yield http_client.fetch("http://example.com")
        do_something_with_response(response)
        self.render("template.html")

或者tornado降级回到5.1.1就没问题了。

官文文档:

https://www.tornadoweb.org/en/branch5.1/web.html#tornado.web.asynchronous

Changed in version 3.1: The ability to use @gen.coroutine without @asynchronous.

Changed in version 4.3: Returning anything but None or a yieldable object from a method decorated with @asynchronous is an error. Such return values were previously ignored silently.

Deprecated since version 5.1: This decorator is deprecated and will be removed in Tornado 6.0. Use coroutines instead.
pip uninstall tornado
pip install tornado==5.1.1

发布了23 篇原创文章 · 获赞 8 · 访问量 2025

猜你喜欢

转载自blog.csdn.net/qq_39610398/article/details/102075150