为什么找不到我的芹菜配置文件?

TIM*_*MEX 20 python django celery

/home/myuser/mysite-env/lib/python2.6/site-packages/celery/loaders/default.py:53:NotConfigured:找不到celeryconfig.py模块!请确保它存在并且可供Python使用.
NotConfigured)

我甚至在我的/ etc/profile和我的虚拟环境中的"激活"中定义了它.但它不是在读它.

Ser*_*hko 25

现在在Celery 4.1中,您可以通过该代码解决该问题(最简单的方法):

import celeryconfig

from celery import Celery

app = Celery()
app.config_from_object(celeryconfig)
Run Code Online (Sandbox Code Playgroud)

例如,小celeryconfig.py:

BROKER_URL = 'pyamqp://'
CELERY_RESULT_BACKEND = 'redis://localhost'
CELERY_ROUTES = {'task_name': {'queue': 'queue_name_for_task'}}
Run Code Online (Sandbox Code Playgroud)

也很简单的方法:

from celery import Celery

app = Celery('tasks')

app.conf.update(
    result_expires=60,
    task_acks_late=True,
    broker_url='pyamqp://',
    result_backend='redis://localhost'
)
Run Code Online (Sandbox Code Playgroud)

或者使用配置类/对象:

from celery import Celery

app = Celery()

class Config:
    enable_utc = True
    timezone = 'Europe/London'

app.config_from_object(Config)
# or using the fully qualified name of the object:
#   app.config_from_object('module:Config')
Run Code Online (Sandbox Code Playgroud)

或者通过设置CELERY_CONFIG_MODULE如何提到

import os
from celery import Celery

#: Set default configuration module name
os.environ.setdefault('CELERY_CONFIG_MODULE', 'celeryconfig')

app = Celery()
app.config_from_envvar('CELERY_CONFIG_MODULE')
Run Code Online (Sandbox Code Playgroud)

另见:


bas*_*sti 21

我的任务模块遇到了类似的问题.一个简单的

# celery config is in a non-standard location
import os
os.environ['CELERY_CONFIG_MODULE'] = 'mypackage.celeryconfig'
Run Code Online (Sandbox Code Playgroud)

在我的包中__init__.py解决了这个问题.


har*_*rry 3

确保 celeryconfig.py 位于运行“celeryd”的同一位置,或者确保它在 Python 路径上可用。