我在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执行任务时,我得到了“操作超时”异常消息。州和ready()总是返回PENDING&假
>>> 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服务器正在运行但是我不知道为什么芹菜抛出异常。
答案 0 :(得分:2)
您可以尝试使用命令
启动worker celery -A proj worker -l info --pool==solo