这是tasks.py
from celery.task import task
@task
def add(x, y):
return x + y
这是celeryconfig.py
print 'importing ' + __file__
BROKER_URL = "amqp://guest:guest@localhost:5672//"
CELERY_RESULT_BACKEND = "amqp"
CELERY_IMPORTS = ("tasks", )
这是我运行的文件。 tasks.py:
from tasks import add
result = add.delay(4, 4)
print result.wait()
程序只是停留在等待方法中。
Celeryd打印出以下错误:
Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.
The full contents of the message body was:
{'retries': 0, 'task': 'tasks.add', 'args': (4, 4), 'expires': None, 'eta': None
, 'kwargs': {}, 'id': '8c973638-4a87-4afa-8a78-958153066215'}
Traceback (most recent call last):
File "d:\python26\lib\site-packages\celery-2.4.5-py2.6.egg\celery\worker\consu
mer.py", line 427, in receive_message
eventer=self.event_dispatcher)
File "d:\python26\lib\site-packages\celery-2.4.5-py2.6.egg\celery\worker\job.p
y", line 297, in from_message
on_ack=on_ack, delivery_info=delivery_info, **kw)
File "d:\python26\lib\site-packages\celery-2.4.5-py2.6.egg\celery\worker\job.p
y", line 261, in __init__
self.task = registry.tasks[self.task_name]
File "d:\python26\lib\site-packages\celery-2.4.5-py2.6.egg\celery\registry.py"
, line 66, in __getitem__
raise self.NotRegistered(key)
NotRegistered: 'tasks.add'
当我运行celeryd.py状态时,我的tasks.add不在这里。
D:\Python26\Lib\site-packages\celery-2.4.5-py2.6.egg\celery\bin>celeryctl.py in
pect registered
<- registered
-> onfirenbpc: OK
* celery.backend_cleanup
* celery.chord
* celery.chord_unlock
* celery.ping
我在Windows和Linux上运行。有同样的问题。
有谁知道为什么?
答案 0 :(得分:1)
您是否将add
方法设为任务?其中一个变体就是使用装饰器:
from celery.decorators import task
@task
def add():
pass