加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – Tornado芹菜不能使用gen.Task或CallBack

发布时间:2020-12-20 13:47:53 所属栏目:Python 来源:网络整理
导读:class AsyncHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): tasks.sleep.apply_async(args=[5],callback=self.on_result) def on_result(self,response): self.write(str(response.result)) self.finish() 提出错误: rais
class AsyncHandler(tornado.web.RequestHandler):

    @tornado.web.asynchronous
    def get(self):
        tasks.sleep.apply_async(args=[5],callback=self.on_result)

    def on_result(self,response):
        self.write(str(response.result))
        self.finish()

提出错误:

raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <bound method AsyncHandler.on_result 
of <__main__.AsyncHandler object at 0x10e7a19d0>> is not JSON serializable

经纪人和后端都使用redis,我刚从中复制过
https://github.com/mher/tornado-celery

当我使用amqp broker和redis后端时,它运行良好,但在使用redis代理时则不行.这是因为龙卷风异步不支持redis经纪人吗?

解决方法

The doc说:

NOTE: Currently callbacks only work with AMQP and Redis backends. To use the Redis backend,you must install tornado-redis.

因此龙卷风芹菜不支持redis作为经纪人…当我使用rabbitmq作为经纪人redis作为后端时它起作用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读