我正在尝试在我的项目中使用 celery 。当我使用 from celery.task.control import revoke
时,PyCharm 突出显示 control
并警告我 cannot find reference 'control' in __init__.py
和PyCharm 还在 revoke
下添加了断线,并警告我Unresolved reference revoke
。
但是当我运行该项目时,celery 工作得很好,调用任务或撤销任务没有任何问题。我的问题是为什么 PyCharm 警告我,将来是否有可能发生任何问题?
celery.py:
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hamclassy.settings')
app = Celery('hamclassy')
# 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 app configs.
app.autodiscover_tasks()
项目/__init__.py:
from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ['celery_app']
最佳答案
当您在 PyCharm 中使用一个 Python 虚拟环境(或只是本地 Python),并为 Celery Worker 使用另一个 Python 环境时,通常会发生这种情况。如果您在 PyCharm 使用的环境中正确安装 Celery,您将不会看到该警告。
只要你想要运行 Celery Worker 的环境正确安装了 Celery 就可以了,你可以忽略 PyCharm 警告,但我建议你在 PyCharm 项目的环境中也安装 Celery 以享受好处PyCharm代码分析等...
关于python - 在 Celery/Django : cannot find reference 'control' in celery. 任务.control,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57035809/