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.
My working configuration:
/home/app/env/bin/celery
Script parameters:
worker -B -n qrc -Q qrc -l info --app=backend.celery
-B
is for celerybeet,-n
is node name,-Q
is queue name,-l
is log level, and--app
is the app name, a django app with celery.py next to settings.py in my case.Working directory:
/home/app/server/
ie my django root folderUnfortunately, 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 thecelery worker
command on it.Note that you don't need to set
--app
here, as the application is defined by the management command viaDJANGO_SETTINGS_MODULE
.Unfortunately, the
celery
management command was a feature of thedjango-celery
library, which isn't supported by Celery 4.x. As of yet, I haven't found a solution for Celery 4.x.You can have a
Run Configuration
to run yourcelery
workers which then allows you to debug simply by clicking thedebug
button. Here is how I set that up in PyCharm 5: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 thebin
folder of the remote interpreter withcelery
installed.I'm using PyCharm 2017 and had to do something very similar to the answers above, but I specifically had to put the full/absolute path name to
celery
in the "Script" fieldAlso, I'm not sure if PyCharm 4 has this feature, but newer versions allow you to attach directly to a running python process by going to Run > Attach to Local Process...
This allows you to run celery however you were before (in the terminal, perhaps) then allow Pycharm to take over
Just add the following config:
Doing so makes celery execute in the same thread as the currently executing thread.