Tornado celery can't use gen.Task or CallBack

2019-05-04 13:07发布

问题:

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 error :

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

The broker and backends all use redis, I just copied from https://github.com/mher/tornado-celery

When I use amqp broker and redis backends it works well, but not when using the redis broker. Is this because tornado async does not support redis broker?

回答1:

The doc says:

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

So tornado-celery does not support redis as a broker... it works when I use rabbitmq as a broker + redis as a backend.