ImportError:无法导入名称'TaskProducer'

时间:2017-04-02 11:41:21

标签: python celery tornado celery-task

我正在使用tcelery与Tornado异步运行任务。 环境:OSX,Python3.4

这是 server.py

from tornado import gen
from tornado import ioloop
from tornado.web import asynchronous, RequestHandler, Application

import tasks

import tcelery
tcelery.setup_nonblocking_producer()


class GenAsyncHandler(RequestHandler):
    @asynchronous
    @gen.coroutine
    def get(self):
        response = yield gen.Task(tasks.sleep.apply_async, args=[3])
        self.write(str(response.result))
        self.finish()

application = Application([
    (r"/gen-async-sleep", GenAsyncHandler)
])


if __name__ == "__main__":
    application.listen(8887)
    ioloop.IOLoop.instance().start()

当我运行服务器文件时,这是返回的错误跟踪:

  

Traceback(最近一次调用最后一次):文件“tornado_async.py”,第7行,   在       import tcelery File“/Users/mohit/anaconda/envs/py34/lib/python3.4/site-packages/tcelery/init.py”,   8号线,在       来自.producer import NonBlockingTaskProducer文件“/Users/mohit/anaconda/envs/py34/lib/python3.4/site-packages/tcelery/producer.py”,   第10行,在       来自celery.app.amqp import TaskProducer ImportError:无法导入名称'TaskProducer'

我该如何解决这个问题? 感谢

1 个答案:

答案 0 :(得分:0)

龙卷风芹菜的版本太低,无法支持芹菜-4.1。您可以通过" python setup.py install"安装tornado-celery。