Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring Celery on Windows

Tags:

windows

celery

I have installed Celery 3.1.5, RabbitMQ server 3.2.1 and Python 2.7.5 on Windows 7 64 bit machine. Here is my code which copied from 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

When I execute task from python shell I got "The operation timed out" exception message. And state and ready() always returns 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.
>>>

I verified RabbitMQ server is running however I have no clue why celery throwing exception.

like image 968
Santro Avatar asked Jan 18 '26 19:01

Santro


2 Answers

You can try to start the worker with command

celery -A proj worker -l info --pool==solo

like image 162
Deja_vu Avatar answered Jan 20 '26 10:01

Deja_vu


Though there are lots of things that can cause the result.get() call to fail -- because there are a lot of steps in the chain between sending the message via the .delay() command, to Celery, to the broker (RabbitMQ), and back to a Celery worker, which does the work, and posts the results back, etc. -- I had this problem and the solution was the one that @Deja_vu suggested of "--pool=solo" (note one equals sign, not two).

The default "pool" option is "prefork" (see http://docs.celeryproject.org/en/latest/reference/celery.bin.worker.html#module-celery.bin.worker ). So this may be a Celery bug in its "prefork" system under Windows: see https://github.com/celery/celery/issues/2146

Related StackOverflow questions:

  • Celery 'Getting Started' not able to retrieve results; always pending
  • Trouble getting result from Celery queue
like image 37
Rudolf Cardinal Avatar answered Jan 20 '26 12:01

Rudolf Cardinal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!