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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章