Archive

Monthly Archives: September 2011

If you’re getting started with Django and Celery and following the instructions at http://django-celery.readthedocs.org/en/latest/getting-started/first-steps-with-django.html, then you might hit the following error when you try to run the example to instantiate the ‘add’ task:

% python
>>> from myapp.tasks import add
/Blah/blah/python2.6/site-packages/celery-2.3.3-py2.6.egg/celery/loaders/default.py:33: NotConfigured: No ‘celeryconfig’ module found! Please make sure it exists and is available to Python.
  “is available to Python.” % (configname, )))

Since no useful information turned up in a Google search for this, I thought I’d post the answer here.

The problem is that Celery doesn’t know that it’s running in the context of a Django app. That information is in your settings.py, if you’ve configured it per the django-celery instructions. So, before you can instantiate your task, you need to do two things:

  1. set DJANGO_SETTINGS_MODULE=settings in your environment
  2. import settings.py before trying to instantiate your task

So:

% DJANGO_SETTINGS_MODULE=settings python
>>> import settings
>>> from myapp.tasks import add
>>> result = add.delay(5, 2)
>>> result.ready()
True
>>> result.result
7
>>> result.successful()
True

 

Advertisements
%d bloggers like this: