Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Celery-Django: Unable to execute tasks asynchronously

I'm trying to run some tasks in the background while users browse my site, but whenever I call a function using Celery it seems to be executed synchronously instead of asynchronously.

e.g., when I call function.delay() the entire site hangs until function.delay() returns. Other methods of calling functions in a similar manner (apply_async, subtasks) exhibit the same problem.

I'm guessing something in either Django or Celery is misconfigured, but I don't know what it is.

Celery configuration in settings.py:

import djcelery
djcelery.setup_loader()

CELERY_RESULT_BACKEND = "amqp"
CELERYBEAT_SCHEDULER = "djcelery.schedulers.DatabaseScheduler"
BROKER_HOST = "localhost"
BROKER_PORT = 5672
BROKER_USER = "test"
BROKER_PASSWORD = "test"
BROKER_VHOST = "testhost"

TEST_RUNNER = "djcelery.contrib.test_runner.run_tests"

CELERY_IMPORTS = ("myapp.tasks",)

BROKER_BACKEND = "memory"
CELERY_ALWAYS_EAGER = True

Trying to start the Celery daemon with "./manage.py celeryd", I get the following output:

[2011-09-23 09:25:38,026: WARNING/MainProcess]  

 -------------- [email protected] v2.2.7
---- **** -----
--- * ***  * -- [Configuration]
-- * - **** ---   . broker:      memory://test@localhost:5672/testhost
- ** ----------   . loader:      djcelery.loaders.DjangoLoader
- ** ----------   . logfile:     [stderr]@WARNING
- ** ----------   . concurrency: 4
- ** ----------   . events:      OFF
- *** --- * ---   . beat:        OFF
-- ******* ----
--- ***** ----- [Queues]
 --------------   . celery:      exchange:celery (direct) binding:celery


[2011-09-23 09:25:38,035: WARNING/MainProcess] [email protected] has started.
like image 608
Tim Burton Avatar asked Feb 22 '23 22:02

Tim Burton


1 Answers

Try removing

CELERY_ALWAYS_EAGER = True

You are explicitly asking celery to execute tasks synchronously. It'll always wait for the result. This setting is useful for writing unit tests etc.

Read http://ask.github.com/celery/configuration.html

like image 197
2 revsuser250145 Avatar answered Feb 25 '23 15:02

2 revsuser250145