我这里用的是celery redis的组合,rabbitmq有些重型。

启动的时候报错,查了下文档,问题确认是全局变量一个参数的问题。

解决办法

    293 
–> 294         meta = self._get_task_meta_for(task_id)
    295         if cache and meta.get(‘status’) == states.SUCCESS:
    296             self._cache[task_id] = meta

AttributeError: ‘DisabledBackend’ object has no attribute ‘_get_task_meta_for’

测试的代码:

The full contents of the message body was:
{‘utc’: True, ‘chord’: None, ‘args’: (0, 0), ‘retries’: 0, ‘expires’: None, ‘task’: ‘tasks.add’, ‘callbacks’: None, ‘errbacks’: None, ‘timelimit’: (None, None), ‘taskset’: None, ‘kwargs’: {}, ‘eta’: None, ‘id’: ’48c13a71-ecda-4ef8-98ce-f223a28c0b97′} (209b)
Traceback (most recent call last):
  File “/usr/local/lib/python2.7/dist-packages/celery/worker/consumer.py”, line 455, in on_task_received
    strategies[name](message, body,
KeyError: ‘tasks.add’
[2014-04-23 09:57:16,673: ERROR/MainProcess] Received unregistered task of type ‘tasks.add’.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.

The full contents of the message body was:
{‘utc’: True, ‘chord’: None, ‘args’: (0, 0), ‘retries’: 0, ‘expires’: None, ‘task’: ‘tasks.add’, ‘callbacks’: None, ‘errbacks’: None, ‘timelimit’: (None, None), ‘taskset’: None, ‘kwargs’: {}, ‘eta’: None, ‘id’: ‘eb1b8772-ca7f-4966-8033-7b4db2a82aa6′} (209b)
Traceback (most recent call last):
  File “/usr/local/lib/python2.7/dist-packages/celery/worker/consumer.py”, line 455, in on_task_received
    strategies[name](message, body,
KeyError: ‘tasks.add’

解决的办法:

最好是用配置文件的方式:

注释下: 

文章的原文,blog.xiaorui.cc



对Python及运维开发感兴趣的朋友可以加QQ群 : 478476595 !!!
{ 2000人qq大群内有各厂大牛,常组织线上分享及沙龙,对高性能及分布式场景感兴趣同学欢迎加入该QQ群 }

另外如果大家觉得文章对你有些作用!   帮忙点击广告. 一来能刺激我写博客的欲望,二来好维护云主机的费用.
如果想赏钱,可以用微信扫描下面的二维码. 另外再次标注博客原地址  xiaorui.cc  ……   感谢!
暂无相关产品

4则回应给“python使用celery做异步任务时的常见的问题”

  1. 那时的风儿说道:

    谢谢。

  2. 有没有Celery编写的示例给发一个呗,jdx2008678@163.com

  3. orangle说道:

    代码高亮调调啊。。。貌似有些错位了

发表评论