what is it?

celery.contrib.rdb is an extended version of pdb that enables remote debugging of processes that doesn’t have terminal access

requirements

sudo apt install telnet

usage

from celery import Celery
app = Celery("project_x")
 
@app.task
def divide(x, y):
    from celery.contrib import rdb
    rdb.set_trace()
 
    # this is for test purposes
    import time
    time.sleep(10)
    return x / y

rdb.set_trace() works like a breakpoint

assuming there’s a config for two containers, one for the celery worker and one for the web server, spin up the containers

docker compose up -d --build
docker compose logs -f
docker compose exec web bash
 
./manage.py shell
 
from django_celery_example.celery import divide
divide.delay(1, 2)

take note of the port: Remote Debugger:6915: Waiting for client.. in the container logs

open a new terminal

docker compose exec celery_worker bash
telnet 127.0.0.1 6915

some debugger commands