Skip to content
Advertisement

in Celery/Django : cannot find reference ‘control’ in celery.task.control

I’m trying to use celery in my project. when I use from celery.task.control import revoke the PyCharm highlight control and warn me cannot find reference 'control' in __init__.py and also PyCharm adds broken line under revoke and warn me Unresolved reference revoke.

But when I run the project, celery is working great without any problem with calling tasks or revoking them. My question is why PyCharm warns me and is it possible in future any problem happen about that?

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']

Advertisement

Answer

This typically happens when you use one Python virtual environment (or just local Python) in your PyCharm, and another Python environment for your Celery worker. If you properly install Celery in the environment used by PyCharm you will not see that warning.

As long as the environment where you want to run your Celery worker in has Celery properly installed you will be fine, and you may ignore the PyCharm warning, but I recommend you install Celery in your PyCharm project’s environment too to enjoy the benefits of PyCharm code analysis, etc…

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement