Skip to content
Go back

How to debug celery tasks

Published:  at  08:00 PM

Debugging Celery Tasks Without Losing Your Mind

When you’re working with Celery, you’ll notice something annoying: depending on what your task does, each run can take minutes. That’s fine in production, but during debugging it’s painful — you fix one line, rerun, wait, repeat. There has to be a better way.

Now, here’s a small trick that can make your life a lot easier. You can drop a simple breakpoint() right inside your Celery task and inspect what’s happening at runtime. Step through the code, check variables, see where things go wrong — just like normal Python debugging.

But when you try it, you’ll quickly run into this BdbQuit. Yeah. Celery basically tells you “nope.”

Here’s why.
By default, Celery uses something called the prefork concurrency mode. That’s great for production because it lets Celery spin up multiple worker processes to handle tasks in parallel. But these workers don’t have a terminal attached — they’re background processes. So when breakpoint() tries to open an interactive prompt, it fails.

The Fix: Use Solo Mode During Development

Here’s the fix — super simple: switch Celery’s concurrency mode to solo when you’re developing. Run your worker like this:

celery -A your_project worker --pool=solo

This makes Celery run everything in a single process, so your breakpoint() will now work as expected. You can step through your code, inspect variables, and actually understand what’s going on — no black box magic.

Use the Right Tool for the Right Stage

That’s it. A one-line change that turns Celery from frustrating to friendly.



Previous Post
What is --force-with-lease in Git?
Next Post
TLS 1.2