【发布时间】:2016-05-12 19:55:29
【问题描述】:
我在 Windows 7 64 位机器上安装了 Celery 3.1.5、RabbitMQ 服务器 3.2.1 和 Python 2.7.5。这是我从first-steps-with-celery复制的代码。
from celery import Celery
app = Celery('tasks', backend='amqp', broker='amqp://guest@localhost//')
@app.task
def add(x, y):
return x + y
当我从 python shell 执行任务时,我收到“操作超时”异常消息。并且 state 和 ready() 总是返回 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.
>>>
我验证了 RabbitMQ 服务器正在运行,但是我不知道为什么 celery 会抛出异常。
【问题讨论】: