Celery 小白遇坑请教:

2017-08-15 17:23:20 +08:00
 Zioyi

初学,按 blog 写最简单的代码:tasks.py

from celery import Celery
app = Celery('tasks', broker='redis://127.0.0.1:6379', backend='redis://127.0.0.1:6379/0')
@app.task
def add(x, y):
    return x + y

启动 celery,一切正常 在同 task.py 目录下进入 python 终端

>>> from tasks import add
>>> result = add.delay(1,2)
>>> result.ready()

总是返回 False(试过 n 遍),当在启动 celery 端已显示成功,请问这是为什么? (celery==3.1.8 redis==3.2)

2608 次点击
所在节点    问与答
3 条回复
MarcoQin
2017-08-15 18:38:08 +08:00
刚查了下官方文档,这样写

AsyncResult.ready()[source]
Return True if the task has executed.

If the task is still running, pending, or is waiting for retry then False is returned.
Zioyi
2017-08-15 19:47:53 +08:00
问题解决,celery -A tasks worker --loglevel=info --pool=solo (添加参数 --pool=solo )
https://cn.v2ex.com/t/177589
eloah
2017-08-15 20:25:15 +08:00
4 已经不支持 windows 了......

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/383161

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX