Celery 服务器错误:“不能将新设置名称与旧设置名称混合使用”

gl3*_*393 2 python celery

我正在使用 celery 服务器和 redis 作为代理和烧瓶。

在 Flask 服务器运行后,我启动了 celery worker (by celery -E -A app.celery worker),但出现以下错误:

Process SpawnPoolWorker-115:
Traceback (most recent call last):
  File "c:\users\a\appdata\local\programs\python\python36\lib\site-packages\kombu\utils\objects.py
    return obj.__dict__[self.__name__]
KeyError: 'default_modules'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\a\appdata\local\programs\python\python36\lib\site-packages\kombu\utils\objects.py
    return obj.__dict__[self.__name__]
KeyError: 'data'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\a\appdata\local\programs\python\python36\lib\site-packages\billiard\process.py",
    self.run()       [.....]
  File "c:\users\a\appdata\local\programs\python\python36\lib\site-packages\celery\app\utils.py",
    for key in sorted(really_left)
celery.exceptions.ImproperlyConfigured:

Cannot mix new setting names with old setting names, please
rename the following settings to use the old format:

include                              -> CELERY_INCLUDE

Or change all of the settings to use the new format :)
Run Code Online (Sandbox Code Playgroud)

但我没有使用设置名称includeCELERY_INCLUDE...

celery = Celery(
    imports=app.import_name,
    result_backend=app.config['CELERY_RESULT_BACKEND'],
    broker_url=app.config['BROKER_URL']
)
Run Code Online (Sandbox Code Playgroud)

这个错误可能来自哪里?

gl3*_*393 7

如果您按照http://flask.pocoo.org/docs/1.0/patterns/celery/ 的建议进行操作, 请celery.conf.update(app.config)在功能中删除 shure make_celery(app)。错误将不再显示。


naa*_*aam 7

当您使用以下两种方式更新 celery 配置时,会出现此错误

1.

celery.conf.update()

2.

celery.conf.task_routes = { 'taskname': {'queue': 'celery'} }

只遵循一种方式

最佳实践是将所有配置保留在celeryconfig.py文件中并导入到 celery 应用程序中

示例celeryconfig.py

broker_url = 'redis://localhost:6379/0'
result_backend = 'redis://localhost:6379/0'

task_serializer = 'json'
result_serializer = 'json'
accept_content = ['json']
timezone = 'Asia/Kolkata'
enable_utc = True
Run Code Online (Sandbox Code Playgroud)

应用程序.py

import celeryconfig

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

希望这能解决您的问题

在此处签出新的小写设置以新格式写入配置