Answer the question
In order to leave comments, you need to log in
How to interrupt a celery task?
Simple example
from celery import Celery
app = Celery('hello', broker='redis://localhost:6379/0')
id_task=''
@app.task(bind=True)
def testtask(self):
id_task=str(self.request.id)
while True:
pass
return 'ok'
def stoptask():
???? (task_id)
Answer the question
In order to leave comments, you need to log in
First, the task must be Abortable:
from celery.contrib.abortable import AbortableTask
@app.task(bind=True, base=AbortableTask)
def testtask(self):
...
while True:
ofwhile not self.is_aborted():
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question