在Windows上configurationCelery

我已经在Windows 7 64位机器上安装了Celery 3.1.5,RabbitMQ server 3.2.1和Python 2.7.5。 这是我的代码,从芹菜第一步复制。

from celery import Celery app = Celery('tasks', backend='amqp', broker='amqp://guest@localhost//') @app.task def add(x, y): return x + y 

当我从python shell执行任务时,我得到了“操作超时”exception消息。 状态和就绪()总是返回PENDING和False。

 >>> from tasks import * >>> result = add.delay(4, 4) >>> result.ready() False >>> result.state 'PENDING' >>> result.get(timeout=20) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\celery\result.py", line 136, in get interval=interval) File "C:\Python27\lib\site-packages\celery\backends\amqp.py", line 154, in wait_for raise TimeoutError('The operation timed out.') celery.exceptions.TimeoutError: The operation timed out. >>> 

我validationRabbitMQ服务器正在运行,但我不知道为什么芹菜抛出exception。

你可以尝试用命令启动worker

celery -A proj worker -l info --pool==solo

虽然有很多事情可能导致result.get()调用失败 – 因为在通过.delay()命令向Celery发送消息到代理(RabbitMQ)之间的链中有很多步骤),然后回到一个做芹菜的工作人员,然后把结果贴回来。等等 – 我遇到了这个问题,解决办法就是@Deja_vu建议的“–pool = solo”(注意一个等于签署,而不是两个)。

默认的“池”选项是“prefork”(请参阅http://docs.celeryproject.org/en/latest/reference/celery.bin.worker.html#module-celery.bin.worker )。 所以这可能是在Windows下的“prefork”系统中的一个Celery错误:请参阅https://github.com/celery/celery/issues/2146

相关的StackOverflow问题:

  • 芹菜“入门”无法检索结果; 总是等待
  • 从芹菜队列中得到结果的麻烦