gpt4 book ai didi

python - celery 与 SQLite : AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for'

转载 作者:太空宇宙 更新时间:2023-11-03 18:21:33 26 4
gpt4 key购买 nike

我想研究celery项目,但是不知道哪里出错了。“tasks.py”文件:

# -*- coding: utf-8 -*-
from celery import Celery

app = Celery('tasks', broker='sqla+sqlite:///celerydb.sqlite')
app.conf.update(
CELERY_RESULT_BACKEND = 'db+sqlite:///results.sqlite',
# CELERY_RESULT_BACKEND = 'redis://localhost/0',
# CELERY_RESULT_BACKEND = 'amqp',
# CELERY_RESULT_BACKEND = 'mongodb://127.0.0.1:27017/',
CELERY_TASK_SERIALIZER = 'json',
CELERY_IGNORE_RESULT = False,
)

@app.task(trail=True)
def add(x, y):
return x + y

@app.task(trail=True)
def mul(x, y):
return x * y

@app.task(trail=True)
def xsum(numbers):
return sum(numbers)

然后我像这样运行 celery 服务:

celery -A tasks worker --loglevel=info  

效果很好。然后我使用 ipython 运行流程脚本:

In [127]: result = add.delay(3,5)
In [128]: result.result

这样的错误:

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-128-a030fb181312> in <module>()
----> 1 result.result

/home/xingming/pyvirt/local/lib/python2.7/site-packages/celery/result.pyc in result(self)
350 If the task raised an exception, this will be the exception
351 instance."""
--> 352 return self._get_task_meta()['result']
353 info = result
354

/home/xingming/pyvirt/local/lib/python2.7/site-packages/celery/result.pyc in _get_task_meta(self)
326 def _get_task_meta(self):
327 if self._cache is None:
--> 328 meta = self.backend.get_task_meta(self.id)
329 if meta:
330 state = meta['status']

/home/xingming/pyvirt/local/lib/python2.7/site-packages/celery/backends/base.pyc in get_task_meta(self, task_id, cache)
292 pass
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'

但是 celery 服务运行良好:

[2014-06-04 11:17:31,656: INFO/MainProcess] Received task: tasks.add[11baa65f-4e18-44b1-80e4-9e81626ca42a]
[2014-06-04 11:17:31,658: INFO/MainProcess] Task tasks.add[11baa65f-4e18-44b1-80e4-9e81626ca42a] succeeded in 0.00117350020446s: 8

这有什么问题吗?

感谢您的帮助!

最佳答案

你没有搞错。 Celery docs充分解释一下:默认情况下,存储任务结果的后端未启用,因此您无法使用任何使用它的函数。如果您想这样做,您需要按照文档配置后端。

关于python - celery 与 SQLite : AttributeError: 'DisabledBackend' object has no attribute '_get_task_meta_for' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24036092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com