Reputation: 63687
Using Python 2.7 and Celery 3.1.25 on Windows, when we run the Celery worker using
celery -A proj worker -l info
we get the error
ImportError: No module named celery
Problem: The worker stops working when we
celeryApp.py
from celery.py
tasks.py
from from .celery import app
to from celeryApp import app
.Why is this happening? How can we fix the problem?
Directory structure
/proj/__init__.py
/proj/celeryApp.py
/proj/tasks.py
/proj/celeryApp.py
from __future__ import absolute_import, unicode_literals
from celery import Celery
app = Celery('tasks',
broker='amqp://jack:[email protected]:5672//',
backend='amqp://',
include=['proj.tasks'])
if __name__ == '__main__':
app.start()
/proj/tasks.py
from __future__ import absolute_import, unicode_literals
from celeryApp import app
@app.task
def add(x, y):
return x + y
Upvotes: 3
Views: 3482
Reputation: 29554
When starting a celery worker, you should name the app to match the python file where the celery module is configured. You should start worker with
celery worker -l info -A tasks
You shouldn't name your config file to celery.py
. This will cause problems when you start importing
from celery import Celery
Your file should be named something else but not celery.py
.
Also in your config file there is no need to add
if __name__ == '__main__':
app.start()
If you are going to explicitly include proj.tasks
make sure proj
is in python path or you can just remove it as you are starting worker with tasks
app.
Upvotes: 1