Celery 任务总是 PENDING [英] Celery task always PENDING

查看:138
本文介绍了Celery 任务总是 PENDING的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在带有 redis 后端的 Windows 上运行 Celery 示例.代码如下:

from celery import Celeryapp = Celery('risktools.distributed.celery_tasks',后端='redis://localhost',broker='redis://localhost')@app.task(ignore_result=False)定义添加(x,y):返回 x + y@app.task(ignore_result=False)def add_2(x, y):返回 x + y

我使用 iPython 控制台启动任务:

<预><代码>>>>result_1 = add.delay(1, 2)>>>result_1.state'待办的'>>>result_2 = add_2.delay(2, 3)>>>result_2.state'待办的'

好像两个任务都没有执行,但是Celery worker的输出显示成功了:

[2014-12-08 15:00:09,262: INFO/MainProcess] 收到任务:risktools.distributed.celery_tasks.add[01dedca1-2db2-48df-a4d6-2f06fe285e45][2014-12-08 15:00:09,267: INFO/MainProcess] 任务 celery_tasks.add[01dedca1-2db2-48df-a4d6-2f06fe285e45] 在 0.0019998550415s 中成功:3[2014-12-08 15:00:24,219: INFO/MainProcess] 收到的任务:risktools.distributed.celery_tasks.add[cb5505ce-cf93-4f5e-aebb-9b2d98a11320][2014-12-08 15:00:24,230: INFO/MainProcess] 任务 celery_tasks.add[cb5505ce-cf93-4f5e-aebb-9b2d98a11320] 在 0.010999917984s 中成功:5

我已尝试根据 Celery 文档,但这些建议都没有用.我做错了什么,如何从 Celery 任务中获得结果?

UPD:我添加了一个没有 ignore_result 参数的任务,但没有任何变化

@app.taskdef add_3(x, y):返回 x + y>>>r = add_3.delay(2, 2)>>>r.state'待办的'

解决方案

根据 Celery 'Getting Started' 无法检索结果;总是待定https://github.com/celery/celery/issues/2146 这是一个 Windows 问题.Celery --pool=solo 选项解决了这个问题.

I try to run Celery example on Windows with redis backend. The code looks like:

from celery import Celery

app = Celery('risktools.distributed.celery_tasks',
             backend='redis://localhost',
             broker='redis://localhost')

@app.task(ignore_result=False)
def add(x, y):
    return x + y

@app.task(ignore_result=False)
def add_2(x, y):
    return x + y

I start the tasks using iPython console:

>>> result_1 = add.delay(1, 2)    
>>> result_1.state
'PENDING'
>>> result_2 = add_2.delay(2, 3)    
>>> result_2.state
'PENDING'

It seems that both tasks were not executed, but Celery worker output shows that they succeeded:

[2014-12-08 15:00:09,262: INFO/MainProcess] Received task: risktools.distributed.celery_tasks.add[01dedca1-2db2-48df-a4d6-2f06fe285e45]
[2014-12-08 15:00:09,267: INFO/MainProcess] Task celery_tasks.add[01dedca1-2db2-48df-a4d6-2f06fe28
5e45] succeeded in 0.0019998550415s: 3
[2014-12-08 15:00:24,219: INFO/MainProcess] Received task: risktools.distributed.celery_tasks.add[cb5505ce-cf93-4f5e-aebb-9b2d98a11320]
[2014-12-08 15:00:24,230: INFO/MainProcess] Task celery_tasks.add[cb5505ce-cf93-4f5e-aebb-9b2d98a1
1320] succeeded in 0.010999917984s: 5

I've tried to troubleshoot this issue according to Celery documentation, but none of the advices were useful. What am I doing wrong and how can I receive results from a Celery task?

UPD: I've added a task without ignore_result parameter, but nothing has changed

@app.task
def add_3(x, y):
    return x + y

>>>r = add_3.delay(2, 2)
>>>r.state
'PENDING'

解决方案

According to Celery 'Getting Started' not able to retrieve results; always pending and https://github.com/celery/celery/issues/2146 it is a Windows issue. Celery --pool=solo option solves the issue.

这篇关于Celery 任务总是 PENDING的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆