1

I have been playing with Celery on Windows 7. Right now, I am going through the Next Steps tutorial: http://docs.celeryproject.org/en/latest/getting-started/next-steps.html

I created a celery.py file:

from __future__ import absolute_import

from celery import Celery

app = Celery('proj',
             broker='amqp://',
             backend='amqp://',
             include=['proj.tasks'])

# app.conf.update(
#   CELERY_TASK_RESULT_EXPIRES=3600,
# )

if __name__ == '__main__':
    app.start()

Then I created a tasks.py file:

from __future__ import absolute_import

from proj.celery import app

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

@app.task
def mul(x, y):
    return x * y

@app.task
def xsum(numbers):
    return sum(numbers)

I then fired up a celery worker in one Powershell. Then in another Powershell I added a couple of integers:

>>> from proj.tasks import add
>>> res = add.delay(2, 2)

In the window running the queue, I got a result right away:

[2014-10-29 09:20:28,875: INFO/MainProcess] Received task: proj.tasks.add[3e5783ef-46a1-44d0-893f-0623e5bc0b09]
[2014-10-29 09:20:28,891: INFO/MainProcess] Task proj.tasks.add[3e5783ef-46a1-44d0-893f-0623e5bc0b09] succeeded in 0.016
0000324249s: 4

However, when I try to retrieve the result in the other window with res.get(), the function just hangs. I've read the tutorial several times and looked on the web and cannot find what the issue is. Could the problem be with using amqp as the backend? I guess amqp sends states as messages instead of storing them.

Oddly enough, if I hit Ctrl+C and query the status of res, I get 'PENDING'.

>>> res.status
'PENDING'

I find this odd because I thought the task was completed. I double checked the ids to make sure.

Looks like the client is configured to use amqp as the backend:

>>> print(res.backend)
<celery.backends.amqp.AMQPBackend object at 0x00000000035C0358>

Looks like ignore_result is set to false.

>>> add
<@task: proj.tasks.add of proj:0x2298390>
>>> add.name
'proj.tasks.add'
>>> add.ignore_result
False
Christopher Spears
  • 1,105
  • 15
  • 32
  • Not sure if this is related, but I did create a task called print_hello where ignore_result was set to true. However, when I checked the value of ignore_result in a shell, the result was false! – Christopher Spears Oct 29 '14 at 19:33

1 Answers1

2

Turns out this is a windows issue. For the sake of honesty, I should say I got the answer from here: Celery 'Getting Started' not able to retrieve results; always pending

Basically, pass the worker the --pool=solo flag:

> C:\Python27\Scripts\celery.exe -A messaging.tasks worker --loglevel=info --pool=solo

I'm unsure what the pool implementation controls though.

Community
  • 1
  • 1
Christopher Spears
  • 1,105
  • 15
  • 32