tornado v6 seems to have dropped tornado.web.asynchronous coroutine. any different way of fixing this in code?

旧巷老猫 提交于 2019-12-11 19:16:13

问题


Migrated torando v5.1 to v6. but asynchronous coroutine seems to have removed. Any suggestions for its fix?

Migrating the project from 2.7 to 3.6, at the same time moving tornado framework from v5.1 to v6.0.2 due to the bug suggested in this [Python code for DynamoDB query is working on v3.6 but not working in python 2.7 strackoverflow thread.

After installing v6 tornado it is breaking with below error.

Python3 xxxx.py

Traceback (most recent call last):
  File "XXXX.py", line 200, in <module>
    class MainHandler(tornado.web.RequestHandler):
  File "XXXX.py", line 201, in MainHandler
    @tornado.web.asynchronous
AttributeError: module 'tornado.web' has no attribute 'asynchronous'

Come across https://github.com/mher/flower/issues/878 thread facing the same issue. is there a fix for this? or any alternative way of presenting things in code?


回答1:


The @asynchronous handler was deprecated in 5.1 and removed in 6.0. Instead of using @asynchronous and callbacks, you should use coroutines (using either @tornado.gen.coroutine or async def).

Note that a few older code examples used to have both @asynchronous and @coroutine on the same method. Putting @asynchronous on a coroutine doesn't do anything, so if you happen to be using both decorators you can just remove @asynchronous without changing anything else.



来源:https://stackoverflow.com/questions/55475879/tornado-v6-seems-to-have-dropped-tornado-web-asynchronous-coroutine-any-differe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!