python - 在 Celery/Django : cannot find reference 'control' in celery. 任务.control

标签 python django celery

我正在尝试在我的项目中使用 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/

相关文章:

python - 保存 Matplotlib 动画

python - 在没有字符串的情况下将 float 分解为以 10 为底的尾数和指数

python - 反转 '' *'',参数 '()' 和关键字参数 '{}' 未找到

flask - Redis错误: ('_kombu.binding.reply.celery.pidbox' ) has been removed from the Redis database

python - 如何使用我的个人计算机在线托管 Python 套接字服务器?

python - 如何在 Django session 模型中设置自定义字段?

python - Heroku 上的 Django manage.py 自定义命令

python - Django,当我返回 status_code 404 或 500 时自定义 404/500

python - 每个用户的 Celery PeriodicTask

python - Django celery 连接错误 : Too many heartbeats missed