3

Here is the tasks.py

from celery.task import task

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

Here is the celeryconfig.py

print 'importing ' + __file__
BROKER_URL = "amqp://guest:guest@localhost:5672//"
CELERY_RESULT_BACKEND = "amqp"
CELERY_IMPORTS = ("tasks", )

Here is the file that i run. tasks.py:

from tasks import add
result = add.delay(4, 4)
print result.wait()

The program just stuck in the wait method.

Celeryd prints the following error:

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'

When I run celeryd.py status, I the tasks.add is not here.

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

I run on windows, and linux as well. There are the same problem.

Does anyone know why?

1 Answer 1

1

Did you set you add method as task? One of variant to do that would use decorator:

from celery.decorators import task

@task
def add():
    pass
Sign up to request clarification or add additional context in comments.

2 Comments

from celery.task import task @task def add(x, y): return x + y
I added the decoration. In fact, I just copied the file from the tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.