django celery error: Unrecoverable error: AttributeError("'EntryPoint' object has no attribute 'module_name'")
django celery error: Unrecoverable error: AttributeError("'EntryPoint' object has no attribute 'module_name'")
我很困惑,因为我是 celery 的新手,所以我不知道这个奇怪的错误,这个错误只发生在设置阶段,每件事都按照 celery 文档中的描述简单配置 https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html
回溯是:
(env) muhammad@huzaifa:~/Desktop/practice/app$ celery -A app worker -l INFO
[2022-04-04 16:21:40,988: WARNING/MainProcess] No hostname was supplied. Reverting to default 'localhost'
[2022-04-04 16:21:40,993: CRITICAL/MainProcess] Unrecoverable error: AttributeError("'EntryPoint' object has no attribute 'module_name'")
Traceback (most recent call last):
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py", line 1250, in backend
return self._local.backend
AttributeError: '_thread._local' object has no attribute 'backend'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/worker/worker.py", line 203, in start
self.blueprint.start(self)
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/bootsteps.py", line 112, in start
self.on_start()
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py", line 136, in on_start
self.emit_banner()
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py", line 170, in emit_banner
' \n', self.startup_info(artlines=not use_image))),
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py", line 232, in startup_info
results=self.app.backend.as_uri(),
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py", line 1252, in backend
self._local.backend = new_backend = self._get_backend()
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py", line 955, in _get_backend
backend, url = backends.by_url(
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/backends.py", line 69, in by_url
return by_name(backend, loader), url
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/backends.py", line 47, in by_name
aliases.update(load_extension_class_names(extension_namespace))
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/utils/imports.py", line 146, in load_extension_class_names
yield ep.name, ':'.join([ep.module_name, ep.attrs[0]])
AttributeError: 'EntryPoint' object has no attribute 'module_name'
初始化文件是:
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ('celery_app',)
celery.py:
import os
from celery import Celery
# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
app = Celery('app', broker='localhost')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request!r}')
供您参考,rabbitmq-server 在本地主机上 运行 这就是为什么我将 BROKER_URL 设置为 'localhost'
rabbitmq-server.service - RabbitMQ Messaging Server
Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-04-03 16:14:04 PKT; 24h ago
Main PID: 1005 (beam.smp)
Status: "Initialized"
Tasks: 91 (limit: 9090)
我不知道为什么会这样,我已经四处寻找了几个小时,但找不到解决方案,甚至连 google 或任何地方的错误都找不到。
任何帮助将不胜感激
谢谢!
您在此处报告了芹菜的新错误:https://github.com/celery/celery/issues/7409
您可以尝试的解决方法是将 celery
的依赖项版本固定到旧版本(即在 celery 错误发布之前)。例如,我的 requirements.txt
包括:
celery==5.2.3
或者在命令行上,您也许可以 运行
pip install celery==5.2.3
(供参考,我在这里看到报告错误的版本是 celery 5.2.5 & click 8.1.2)
希望这在上游得到修复,我们可以删除我们的版本引脚。
遇到同样的错误将celery版本降级到5.2.0,成功了
我将 celery 降级到 5.2.3,一切正常。
谢谢@Jeff-G
我今天遇到了同样的问题。所以,我只是将芹菜版本降级到 5.2.3
pip install celery==5.2.3
成功了
我很困惑,因为我是 celery 的新手,所以我不知道这个奇怪的错误,这个错误只发生在设置阶段,每件事都按照 celery 文档中的描述简单配置 https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html 回溯是:
(env) muhammad@huzaifa:~/Desktop/practice/app$ celery -A app worker -l INFO
[2022-04-04 16:21:40,988: WARNING/MainProcess] No hostname was supplied. Reverting to default 'localhost'
[2022-04-04 16:21:40,993: CRITICAL/MainProcess] Unrecoverable error: AttributeError("'EntryPoint' object has no attribute 'module_name'")
Traceback (most recent call last):
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py", line 1250, in backend
return self._local.backend
AttributeError: '_thread._local' object has no attribute 'backend'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/worker/worker.py", line 203, in start
self.blueprint.start(self)
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/bootsteps.py", line 112, in start
self.on_start()
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py", line 136, in on_start
self.emit_banner()
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py", line 170, in emit_banner
' \n', self.startup_info(artlines=not use_image))),
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/apps/worker.py", line 232, in startup_info
results=self.app.backend.as_uri(),
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py", line 1252, in backend
self._local.backend = new_backend = self._get_backend()
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/base.py", line 955, in _get_backend
backend, url = backends.by_url(
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/backends.py", line 69, in by_url
return by_name(backend, loader), url
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/app/backends.py", line 47, in by_name
aliases.update(load_extension_class_names(extension_namespace))
File "/home/muhammad/Desktop/practice/env/lib/python3.8/site-packages/celery/utils/imports.py", line 146, in load_extension_class_names
yield ep.name, ':'.join([ep.module_name, ep.attrs[0]])
AttributeError: 'EntryPoint' object has no attribute 'module_name'
初始化文件是:
from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app
__all__ = ('celery_app',)
celery.py:
import os
from celery import Celery
# Set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
app = Celery('app', broker='localhost')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request!r}')
供您参考,rabbitmq-server 在本地主机上 运行 这就是为什么我将 BROKER_URL 设置为 'localhost'
rabbitmq-server.service - RabbitMQ Messaging Server
Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2022-04-03 16:14:04 PKT; 24h ago
Main PID: 1005 (beam.smp)
Status: "Initialized"
Tasks: 91 (limit: 9090)
我不知道为什么会这样,我已经四处寻找了几个小时,但找不到解决方案,甚至连 google 或任何地方的错误都找不到。 任何帮助将不胜感激 谢谢!
您在此处报告了芹菜的新错误:https://github.com/celery/celery/issues/7409
您可以尝试的解决方法是将 celery
的依赖项版本固定到旧版本(即在 celery 错误发布之前)。例如,我的 requirements.txt
包括:
celery==5.2.3
或者在命令行上,您也许可以 运行
pip install celery==5.2.3
(供参考,我在这里看到报告错误的版本是 celery 5.2.5 & click 8.1.2)
希望这在上游得到修复,我们可以删除我们的版本引脚。
遇到同样的错误将celery版本降级到5.2.0,成功了
我将 celery 降级到 5.2.3,一切正常。
谢谢@Jeff-G
我今天遇到了同样的问题。所以,我只是将芹菜版本降级到 5.2.3
pip install celery==5.2.3
成功了