无法从Celery队列获取结果 [英] Trouble getting result from Celery queue

查看:72
本文介绍了无法从Celery队列获取结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Windows 7上使用Celery.现在,我正在阅读下一步"教程:

I have been playing with Celery on Windows 7. Right now, I am going through the Next Steps tutorial: http://docs.celeryproject.org/en/latest/getting-started/next-steps.html

我创建了一个celery.py文件:

I created a celery.py file:

from __future__ import absolute_import

from celery import Celery

app = Celery('proj',
             broker='amqp://',
             backend='amqp://',
             include=['proj.tasks'])

# app.conf.update(
#   CELERY_TASK_RESULT_EXPIRES=3600,
# )

if __name__ == '__main__':
    app.start()

然后我创建了一个task.py文件:

Then I created a tasks.py file:

from __future__ import absolute_import

from proj.celery import app

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

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

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

然后我在一个Powershell中解雇了一名芹菜工人.然后在另一个Powershell中,我添加了两个整数:

I then fired up a celery worker in one Powershell. Then in another Powershell I added a couple of integers:

>>> from proj.tasks import add
>>> res = add.delay(2, 2)

在运行队列的窗口中,我立即得到一个结果:

In the window running the queue, I got a result right away:

[2014-10-29 09:20:28,875: INFO/MainProcess] Received task: proj.tasks.add[3e5783ef-46a1-44d0-893f-0623e5bc0b09]
[2014-10-29 09:20:28,891: INFO/MainProcess] Task proj.tasks.add[3e5783ef-46a1-44d0-893f-0623e5bc0b09] succeeded in 0.016
0000324249s: 4

但是,当我尝试使用res.get()在另一个窗口中检索结果时,该函数只是挂起.我已经多次阅读了该教程,并在网上查看了一下,却找不到问题所在.问题可能出在使用amqp作为后端吗?我猜想amqp会将状态作为消息发送,而不是存储它们.

However, when I try to retrieve the result in the other window with res.get(), the function just hangs. I've read the tutorial several times and looked on the web and cannot find what the issue is. Could the problem be with using amqp as the backend? I guess amqp sends states as messages instead of storing them.

奇怪的是,如果我按Ctrl + C并查询res的状态,则会显示待处理".

Oddly enough, if I hit Ctrl+C and query the status of res, I get 'PENDING'.

>>> res.status
'PENDING'

我觉得这很奇怪,因为我认为任务已经完成.我仔细检查了ID以确保结果.

I find this odd because I thought the task was completed. I double checked the ids to make sure.

看起来客户端已配置为使用amqp作为后端:

Looks like the client is configured to use amqp as the backend:

>>> print(res.backend)
<celery.backends.amqp.AMQPBackend object at 0x00000000035C0358>

好像ignore_result设置为false.

Looks like ignore_result is set to false.

>>> add
<@task: proj.tasks.add of proj:0x2298390>
>>> add.name
'proj.tasks.add'
>>> add.ignore_result
False

推荐答案

原来是Windows问题.为了诚实起见,我应该说我从这里得到了答案:

Turns out this is a windows issue. For the sake of honesty, I should say I got the answer from here: Celery 'Getting Started' not able to retrieve results; always pending

基本上,向工作人员传递--pool = solo标志:

Basically, pass the worker the --pool=solo flag:

> C:\Python27\Scripts\celery.exe -A messaging.tasks worker --loglevel=info --pool=solo

我不确定池实现可以控制什么.

I'm unsure what the pool implementation controls though.

这篇关于无法从Celery队列获取结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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