在 Celery/Django 中:在 celery.task.control 中找不到引用 'control'
in Celery/Django : cannot find reference 'control' in celery.task.control
我正在尝试在我的项目中使用芹菜。当我使用 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()
project/__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 警告,但我建议你安装 Celery在您的 PyCharm 项目环境中也可以享受 PyCharm 代码分析等的好处...
'control' 模块位于 celery.app 而不是 celery.task 。按照您设置的方式导入 'revoke' 是行不通的。
我正在尝试在我的项目中使用芹菜。当我使用 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()
project/__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 警告,但我建议你安装 Celery在您的 PyCharm 项目环境中也可以享受 PyCharm 代码分析等的好处...
'control' 模块位于 celery.app 而不是 celery.task 。按照您设置的方式导入 'revoke' 是行不通的。