为什么找不到我的芹菜配置文件? [英] Why can't it find my celery config file?
本文介绍了为什么找不到我的芹菜配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
/home/myuser/mysite-env/lib/python2.6/site-packages/celery/loaders/default.py:53:
NotConfigured:No celeryconfig.py $找到b $ b个模块!请确保
存在并且可用于Python。
未配置)
/home/myuser/mysite-env/lib/python2.6/site-packages/celery/loaders/default.py:53: NotConfigured: No celeryconfig.py module found! Please make sure it exists and is available to Python.
NotConfigured)
我什至已定义它在我的/ etc / profile中,也在我的虚拟环境的激活中。
I even defined it in my /etc/profile and also in my virtual environment's "activate". But it's not reading it.
推荐答案
现在在Celery 4.1中,您可以通过该代码解决该问题(最简单的方法):
import celeryconfig
from celery import Celery
app = Celery()
app.config_from_object(celeryconfig)
例如小 celeryconfig.py :
BROKER_URL = 'pyamqp://'
CELERY_RESULT_BACKEND = 'redis://localhost'
CELERY_ROUTES = {'task_name': {'queue': 'queue_name_for_task'}}
也很简单:
from celery import Celery
app = Celery('tasks')
app.conf.update(
result_expires=60,
task_acks_late=True,
broker_url='pyamqp://',
result_backend='redis://localhost'
)
或使用配置c lass / object:
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')
或者通过设置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')
另请参阅:
- 创建配置: http://docs.celeryproject.org/en /latest/userguide/application.html#configuration
- 配置字段: http://docs.celeryproject.org/en/latest/userguide/configuration.html
- Create config: http://docs.celeryproject.org/en/latest/userguide/application.html#configuration
- Configuration fields: http://docs.celeryproject.org/en/latest/userguide/configuration.html
这篇关于为什么找不到我的芹菜配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文