django 1.7rc3和芹菜3.13 - AppRegistryNotReady

w--*_*w-- 6 python django celery

这对我不起作用

$> cat/etc/lsb-release
DISTRIB_ID = Ubuntu
DISTRIB_RELEASE = 12.04
DISTRIB_CODENAME =精确
DISTRIB_DESCRIPTION ="Ubuntu 12.04.2 LTS"

django 1.7rc3
芹菜3.1.13
python 2.7

我试图跑

celery worker -A <project_name>
Run Code Online (Sandbox Code Playgroud)

我明白了

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.
Run Code Online (Sandbox Code Playgroud)

runserver命令工作正常,所以我不认为它与我的设置有关?

python manage.py runserver 0.0.0.0:8080
Run Code Online (Sandbox Code Playgroud)

我仔细检查了celery.py并确认它具有以下行的正确值:

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')

app = Celery('proj')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
Run Code Online (Sandbox Code Playgroud)

还有别的我应该做的吗?

Ste*_*eve 5

Django 1.7现在需要对独立脚本进行不同的初始化.在manage.py上下文之外运行时,您现在需要包括:

import django
django.setup()
Run Code Online (Sandbox Code Playgroud)

尝试app = Celery('proj')在脚本之前添加它.


w--*_*w-- 1

我发现失败的原因是因为我的其中一个任务中有这个。py

CURRENT_DOMAIN = Site.objects.get_current().domain
Run Code Online (Sandbox Code Playgroud)

我现在已经回避了这个问题

CURRENT_DOMAIN = lambda: Site.objects.get_current().domain
Run Code Online (Sandbox Code Playgroud)

目前正在等待 github 上是否有人愿意提供更好的推荐。 https://github.com/celery/celery/issues/2227

如果我得到一个就会更新。如果没有,可能只会执行一个辅助函数,延迟返回我想要的值。

根据 celery 作者的建议进行更新
,我重构了我的代码,因此我不会在模块级别进行该调用。
他还通过确保在导入任务模块之前调用 django.setup() 解决了这个问题
https://github.com/celery/celery/issues/2227