Categories
Python Answers

How to cancel an already executing task with Celery and Python?

Spread the love

Sometimes, we want to cancel an already executing task with Celery and Python.

In this article, we’ll look at how to cancel an already executing task with Celery and Python.

How to cancel an already executing task with Celery and Python?

To cancel an already executing task with Celery and Python, we can use the revoke function.

For instance, we write

from celery.task.control import revoke
revoke(task_id, terminate=True)

to call revoke with the task_id of the task to stop.

And we set terminate to True to terminate the task.

Conclusion

To cancel an already executing task with Celery and Python, we can use the revoke function.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *