How can I use PyCharm to locally debug a Celery worker?
This is what I do to run celery
Go to Edit Configuration
, then select the '+' icon to add new Python script and enter the celery path, other parameters and working directory. You can specify environment variables and bottom of that you have the option to select parent environment to include as well. Also, don't forget to choose your python interpreter for taking care of virtual environment.
Shaggy Frog
Remote: Yes Technologies: Everything/whatever. Last 3-4 years: Python (Django), Kotlin, Java (Spring), JavaScript. Also last 11 years: iOS/OSX (C/C++/Objective-C), Bash, Perl. MSc in AI (heuristic search). LinkedIn: https://www.linkedin.com/in/thomashauk Hacker News: https://news.ycombinator.com/user?id=shaggyfrog First Computer: Atari 800 (Logo and BASIC) Cake: YES Copy & Paste Messages: no thank you I'm a proud generalist. I add value. I care about my work. I get stuff done. I deliver. Send me an e-mail!
Updated on July 09, 2022Comments
-
Shaggy Frog almost 2 years
I have an existing Django project with a virtualenv. After activating the venv, I can run Celery just with the command
celery
. This works on Windows, OS X and Linux.I wanted to try PyCharm on Windows, and I'm able to get it to run my Django server (using the project's venv), but I also want to run Celery, so I can debug that as well.
I can't find a simple, straightforward guide to setting up PyCharm so I can debug Celery (in a manner will work with PyCharm on any platform).
-
Ícaro almost 7 yearsIf you are using
virtualenv
, you might want to change theScript
path to point to yourenv
's location, like so:env/bin/celery
-
phobic over 6 yearsI noticed that this does not work with
CELERY_ALWAYS_EAGER = True
, as it does not stop on break points. Try setting it to False instead, which should be the default anyway. -
Hrishabh Gupta over 6 years@phobic it is not needed to set always_eager=True, you run the script in debug mode, it will work.
-
Jonathan Geisler about 6 yearsThis works on Linux, but last I've tried this doesn't work on Windows (as OP requested). The standalone
celery
command is a batch file there, so PyCharm cannot attach the Python debugger to it. -
Jonathan Geisler about 6 yearsI've outlined a workaround for Celery 3.x on Windows here: stackoverflow.com/a/48868014/6278
-
Jorge Arévalo over 5 yearsI run it with the same configuration. This should be marked as the right response.
-
frenzy over 4 yearsFor Celery 4.x and better Celery 3.x solution see this stackoverflow.com/a/57817731/4474576
-
user142295 over 3 yearsThis is not working for me. I use Celery 5.x on Linux-5.4.0-42-generic-x86_64-with-glibc2.10. I set up the project as described, then run the abovementioned config in debug mode. The code stops at my breakpoint (at least pycharm makes me think it did; in debug window, I have Debugger and Console tabs, and the breakpoint line becomes blue in the background). And then it hangs. In Console, I cannot print anything, in debugger, nothing is shown, and I cannot advance the code (at least, not by any means known to me).
-
yyunikov almost 2 yearsIf you've been experiencing
The curl client requires the pycurl library
error, uninstallingpycurl
and installing withPYCURL_SSL_LIBRARY=openssl LDFLAGS="-L/usr/local/opt/openssl/lib" CPPFLAGS="-I/usr/local/opt/openssl/include" pip install --no-cache-dir pycurl
helped me.