Celery 4.2-Django RecursionError:超过最大递归深度

时间:2018-08-11 02:27:36

标签: django celery supervisor

我的__init__.py文件

from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app

__all__ = ('celery_app',)

我的celery.py文件

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
app = Celery('myproject')

app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()

我的 /etc/supervisor/conf.d/celery.conf 文件:

[program:]
command=/home/user/venv/bin/celery -A myproject worker --loglevel=INFO
environment=PYTHONPATH=/home/user/project-folder
user=user
numprocs=1
autostart=true
autorestart=true
stdout_logfile=/home/user/logs/celery.log
stderr_logfile=/home/user/logs/celery.log
startssecs=10
stopwaitsecs = 600
stopasgroup=true
priority=100

这是celery.log

中错误消息的最后一部分
File "/home/user/venv/lib/python3.6/site-packages/celery/loaders/base.py", line 131, in config_from_object
   self._conf = force_mapping(obj)
File "/home/user/venv/lib/python3.6/site-packages/celery/utils/collections.py", line 48, in force_mapping
   return DictAttribute(m) if not isinstance(m, Mapping) else m
File "/home/user/venv/lib/python3.6/abc.py", line 183, in __instancecheck__
   subclass = instance.__class__
File "/home/user/venv/lib/python3.6/site- packages/django/utils/functional.py", line 215, in inner
   self._setup()
File "/home/user/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
   self._wrapped = Settings(settings_module)
File "/home/user/venv/lib/python3.6/site-packages/django/conf/__init__.py", line 106, in __init__
   mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/user/venv/lib/python3.6/importlib/__init__.py", line 126, in import_module
   return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 951, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 894, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
File "<frozen importlib._bootstrap_external>", line 1129, in _get_spec
File "<frozen importlib._bootstrap_external>", line 1273, in find_spec
File "<frozen importlib._bootstrap_external>", line 1231, in _get_spec
File "<frozen importlib._bootstrap_external>", line 556, in 
spec_from_file_location
RecursionError: maximum recursion depth exceeded

我不知道此配置有什么问题吗?

4 个答案:

答案 0 :(得分:1)

from django.conf import settings

app.config_from_object(settings, namespace='CELERY')

实际上settings进入那里。

答案 1 :(得分:0)

您不应将自己的celery应用导入到您的__init__.py文件中。删除它,它将解决您无限的启动导入循环。本质上,您的celery应用程序启动了django设置模块的初始化,该初始化又加载了应用程序并尝试重新加载项目__init__.py文件,该文件加载了您的celery文件,然后尝试重新加载了设置文件,因为它尚未初始化反过来。 。 。 (您知道了)。

答案 2 :(得分:0)

删除句子时,我也遇到同样的问题

app.autodiscover_tasks()

然后它起作用。因此,我认为问题是由于此而发生的。 也许我们应该指定此功能的配置。

答案 3 :(得分:0)

万一它对某人有帮助-我有一个类似的问题,它是由on_configure类的重写Celery方法中的异常引起的。我认为阻止Celery._load_config方法正常执行的任何操作都可能导致“超出最大递归深度”错误。