我的项目使用的是Python 3.4,Django 1.7.1,Celery 3.1。我有RabbitMQ按预期运行。
项目结构是开箱即用的标准:
my_project/
my_project/
settings.py
celery.py
...
我知道有几个重复的问题,但他们并没有为我解决问题。我的celery.py文件如下:
from __future__ import absolute_import
import os
import django
from celery import Celery
from django.conf import settings
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_project.settings')
django.setup()
app = Celery('my_project')
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
设定:
BROKER_URL = 'amqp://guest:guest@localhost:5672//'
当我尝试跑步时:
$ celery -A my_project worker -l debug
我收到了芹菜属性错误。
完整追溯:
Traceback (most recent call last):
File "/usr/local/bin/celery", line 9, in <module>
load_entry_point('celery==3.1.17', 'console_scripts', 'celery')()
File "/usr/local/lib/python3.4/dist-packages/celery-3.1.17-py3.4.egg/celery/__main__.py", line 30, in main
main()
File "/usr/local/lib/python3.4/dist-packages/celery-3.1.17-py3.4.egg/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/usr/local/lib/python3.4/dist-packages/celery-3.1.17-py3.4.egg/celery/bin/celery.py", line 769, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/usr/local/lib/python3.4/dist-packages/celery-3.1.17-py3.4.egg/celery/bin/base.py", line 305, in execute_from_commandline
argv = self.setup_app_from_commandline(argv)
File "/usr/local/lib/python3.4/dist-packages/celery-3.1.17-py3.4.egg/celery/bin/base.py", line 465, in setup_app_from_commandline
self.app = self.find_app(app)
File "/usr/local/lib/python3.4/dist-packages/celery-3.1.17-py3.4.egg/celery/bin/base.py", line 485, in find_app
return find_app(app, symbol_by_name=self.symbol_by_name)
File "/usr/local/lib/python3.4/dist-packages/celery-3.1.17-py3.4.egg/celery/app/utils.py", line 240, in find_app
found = sym.celery
AttributeError: 'module' object has no attribute 'celery'
我做错了什么?
答案 0 :(得分:1)
你的配置很好。但是当启动worker时,您需要指定应用程序名称或具有celery对象的文件。但是你只是指定了没有celery对象的my_project
。
celery worker -A my_project.celery -l debug
应该解决问题。
还要将celery.py重命名为celery_conf.py或其他内容。
答案 1 :(得分:0)
原来这是一个安装问题。我只是重置了我的virtualenv,重新安装了芹菜和中提琴。抱歉浪费了每个人的时间。