我正在尝试使用带有redis的django芹菜作为经纪人。我的应用名称之一是用户,其模型由其他应用导入。当我运行django服务器时,它启动没有任何错误,一切正常。
但是当我尝试使用命令" celery -A project worker -l INFO"启动芹菜工作时,我收到以下错误:
Traceback (most recent call last):
File "/usr/local/bin/celery", line 11, in <module>
sys.exit(main())
File "/usr/local/lib/python2.7/dist-packages/celery/__main__.py", line 30, in main
main()
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 81, in main
cmd.execute_from_commandline(argv)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 793, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 311, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 785, in handle_argv
return self.execute(command, argv)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/celery.py", line 717, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/usr/local/lib/python2.7/dist-packages/celery/bin/worker.py", line 179, in run_from_argv
return self(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/base.py", line 274, in __call__
ret = self.run(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/bin/worker.py", line 212, in run
state_db=self.node_format(state_db, hostname), **kwargs
File "/usr/local/lib/python2.7/dist-packages/celery/worker/__init__.py", line 95, in __init__
self.app.loader.init_worker()
File "/usr/local/lib/python2.7/dist-packages/celery/loaders/base.py", line 128, in init_worker
self.import_default_modules()
File "/usr/local/lib/python2.7/dist-packages/celery/loaders/base.py", line 116, in import_default_modules
signals.import_modules.send(sender=self.app)
File "/usr/local/lib/python2.7/dist-packages/celery/utils/dispatch/signal.py", line 166, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/local/lib/python2.7/dist-packages/celery/fixups/django.py", line 73, in on_import_modules
self.worker_fixup.validate_models()
File "/usr/local/lib/python2.7/dist-packages/celery/fixups/django.py", line 158, in validate_models
django_setup()
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/path_to_project/project/app1/models.py", line 2, in <module>
from app1.models import *
File "/path_to_project/project/project/models.py", line 9, in <module>
from user.models import *
ImportError: No module named models
这里需要注意的是,它表示没有名为模型的模块和不没有名为 user.models 的模块。这可能意味着与其他文件存在一些冲突,尽管我已经进行了双重检查,项目目录或app1目录中没有user.py。如果我重命名app&#34; user&#34;到&#34; user2&#34;工人开始了。另外值得注意的是芹菜在某个时候开始很好的事实。从那时起代码已经改变,但没有添加应用程序。
我的项目具有以下结构(仅显示相关部分)
- project
- project
- celery.py
- models.py
- user
- models.py
- app1
- models.py
- tasks.py
和celery.py是
from __future__ import absolute_import
import os
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', 'project.settings')
app = Celery('project')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
CELERY配置
BROKER_URL = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
由于