Kevin Meyer Kevin Meyer - 1 year ago 92
Python Question

Why does Celery NOT throw an Exception when the underlying task throws one

Celery doesn't seem to be handling exceptions properly.

If I have task:

def errorTest():
raise Exception()

and then I call

r = errorTest.delay()
In [8]: r.result

In [9]: r.state
Out[9]: 'PENDING'

And it will hang like this indefinitely.

Going and checking the logs shows that the error IS getting thrown in the task (and if you want the message, ask), and I know that the backend and everything is set up properly because other tasks just work and return results correctly.

Is there something funky that I need to do to catch exceptions in Celery?

/Celery version is 3.0.13, broker is RabbitMQ running on my local machine

Answer Source

You can define an on_failure function in your Task subclass to handle them correctly. If you're just looking to find out what happened you can setup error email notifications that will send you the stack trace in your celery config.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download