'Celery + Django on Windows: debugging asynchronous tasks
With Django 1.8 I used Django-celery to run asynchronous tasks and I was able to debug them in my IDE (either PyCharm or Eclipse+PyDev) just launching "python celery worker" in debug mode.
Django-celery doesn't support Django 2.2, so I have to run pure celery.exe.
Celery docs say that I have to add pdb to my code and run debug via console.
How can I debug these tasks as I did before, adding breakpoints dynamically from my IDE?
Solution 1:[1]
You can use CELERY_ALWAYS_EAGER = True setting in you development env. If this is True, all tasks will be executed locally without sending it to a queue.
Solution 2:[2]
You can use celery.contrib.rdb, an extension of pdb.
from celery.contrib import rdb
from celery.task import task
@task
def add(x,y):
result=× + y
rdb.set_trace() #set breakpoint
return x+y
Open next terminal and type
telnet localhost 6900
Now you are in debug mode.
Solution 3:[3]
Telnet solution doesn't work for me.
But I was able to debug my tasks with pdb.
Add breakpoint: pdb.set_trace().
Then just run worker with -l warning, it will prevent printing of excessive info.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | neverwalkaloner |
| Solution 2 | |
| Solution 3 | Ledorub |
