我很困惑,因为我是芹菜新手,所以我不知道一个奇怪的错误,这个错误只发生在设置阶段,每件事都只是按照芹菜文档中的描述进行配置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'
init文件是:
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}')
供您参考,rabbitmqserver正在localhost上运行,这就是为什么我将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)
idk为什么会发生这种情况,我已经四处寻找了大约几个小时,却找不到解决方案,甚至在谷歌或任何地方都找不到错误。任何帮助都将不胜感激谢谢
您遇到了一个关于芹菜的新错误,报告如下:https://github.com/celery/celery/issues/7409
您可以尝试的解决方法是将celery
的依赖关系的版本固定到较旧的版本(即,在发布芹菜错误之前(。例如,我的requirements.txt
包括:
celery==5.2.3
或者在命令行上,你可能只能运行
pip install celery==5.2.3
(作为参考,我在这里看到错误报告的版本是芹菜5.2.5和点击8.1.2(
希望这能在上游得到修复,我们可以删除我们的版本引脚。
遇到同样的错误,将芹菜版本降级为5.2.0,并在中工作
我将芹菜降级到5.2.3,一切都恢复正常。
谢谢@Jeff-G
我今天遇到了同样的问题。所以,我只是将芹菜版本降级为5.2.3
pip install celery==5.2.3
它起到了的作用
这是后来者。我很难让Celery作为一个简单的例子,并不断地遇到以下错误。
AttributeError: 'EntryPoints' object has no attribute 'get'
我尝试将Kombu和Celery的版本分别固定为4.6和5.2.3,这是fella开发人员在这条路上推荐的。
唯一对我有用的是破解kombu/utils/fight.py文件。
根据错误的线索,我修改了第82行,并更改了以下代码:
for ep in importlib_metadata.entry_points().get(namespace, [])
到以下
for ep in importlib_metadata.entry_points(group ='namespace')
我确信这不是一种正确的方法,至少从项目中使用第三方库的角度来看是这样,因为修改不是来自源代码,因此在更新库时很容易中断,以这种方式解决问题是不可取的。但至少它在POC练习中对我有所帮助。
如果你像我一样陷入困境,你可以尝试上面的方法。此外,如果有人在不破坏编码基本原则的情况下提出任何建议或解决方法,我将很高兴听到,这不涉及更改未来可能发展的库并破坏自定义代码。