How can I use PyCharm to locally debug a Celery worker?

21,709

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.

running celery using pycharm

Share:
21,709
Shaggy Frog
Author by

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, 2022

Comments

  • Shaggy Frog
    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
    Ícaro almost 7 years
    If you are using virtualenv, you might want to change the Script path to point to your env's location, like so: env/bin/celery
  • phobic
    phobic over 6 years
    I 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
    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
    Jonathan Geisler about 6 years
    This 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
    Jonathan Geisler about 6 years
    I've outlined a workaround for Celery 3.x on Windows here: stackoverflow.com/a/48868014/6278
  • Jorge Arévalo
    Jorge Arévalo over 5 years
    I run it with the same configuration. This should be marked as the right response.
  • frenzy
    frenzy over 4 years
    For Celery 4.x and better Celery 3.x solution see this stackoverflow.com/a/57817731/4474576
  • user142295
    user142295 over 3 years
    This 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
    yyunikov almost 2 years
    If you've been experiencing The curl client requires the pycurl library error, uninstalling pycurl and installing with PYCURL_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.