How do I enable remote celery debugging in PyCharm?

15,793

Solution 1

You can have a Run Configuration to run your celery workers which then allows you to debug simply by clicking the debug button. Here is how I set that up in PyCharm 5:

pycharm celery

You need to set up a remote python interpreter and then set other configs like the image above. Note that the Working directory is pointing to the bin folder of the remote interpreter with celery installed.

Solution 2

For Windows, tested in with Celery >= 4.0

Add a new (Run/Debug) configuration of type "Python":

Then, Under configuration tab: switch the first option (Target to run) from "Script path" to "Module name" and fill in the value:

celery.bin.celery

like the snapshot below:

enter image description here

Solution 3

Just add the following config:

from celery import current_app
current_app.conf.CELERY_ALWAYS_EAGER = True
current_app.conf.CELERY_EAGER_PROPAGATES_EXCEPTIONS = True

Doing so makes celery execute in the same thread as the currently executing thread.

Solution 4

Unfortunately, most solutions don't work on Windows. (There was a separate question specifically about that, but unfortunately it got closed as a duplicate of this one. So I'll answer that question here now.)

The problem is that on Windows, the standalone celery command is a batch file, so PyCharm cannot attach the Python debugger to it.

Up until Celery 3.x, you can create a manage.py run configuration and call the celery worker command on it.

Screenshot of PyCharm run configuration for running manage.py celery worker

Note that you don't need to set --app here, as the application is defined by the management command via DJANGO_SETTINGS_MODULE.

Unfortunately, the celery management command was a feature of the django-celery library, which isn't supported by Celery 4.x. As of yet, I haven't found a solution for Celery 4.x.

Solution 5

in Windows , Add the following params in your debugging conf in Pycharm

-A YouAppName worker  --loglevel=debug -P solo --without-gossip --without-mingle --without-heartbeat
Share:
15,793
Ryan
Author by

Ryan

SOreadytohelp

Updated on June 14, 2022

Comments

  • Ryan
    Ryan about 2 years

    I'm trying to find some instructions on how to enable PyCharm debugging within my celery processes on a remote machine. The remote machine is running Ubuntu 14.04.

    I am running PyCharm 4.x.

    I've seen some other information that alludes others have it working, but haven't been able to locate any proper instructions.

  • Pnia
    Pnia almost 4 years
    Thanks, was looking for this!
  • vicusbass
    vicusbass over 3 years
    Life-saving comment
  • Dequn
    Dequn over 3 years
    Thanks, I found -P solo must be added
  • safhac
    safhac over 3 years
    this solution worked for me in pycharm 2020 pro edit: i suppose workdir was what's missing
  • Code-Apprentice
    Code-Apprentice about 3 years
    I had to put the full path to the celery executable in IntelliJ 2021.1.
  • youreyecheek
    youreyecheek over 2 years
    I had to use module name celery, not celery.bin.celery