V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Zioyi
V2EX  ›  问与答

Celery 小白遇坑请教:

  •  
  •   Zioyi · 2017-08-15 17:23:20 +08:00 · 2607 次点击
    这是一个创建于 2439 天前的主题,其中的信息可能已经有所发展或是发生改变。

    初学,按 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)

    3 条回复    2017-08-15 20:25:15 +08:00
    MarcoQin
        1
    MarcoQin  
       2017-08-15 18:38:08 +08:00   ❤️ 1
    刚查了下官方文档,这样写

    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
        2
    Zioyi  
    OP
       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
        3
    eloah  
       2017-08-15 20:25:15 +08:00
    4 已经不支持 windows 了......
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4381 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 10:08 · PVG 18:08 · LAX 03:08 · JFK 06:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.