In the django project, I use celery to run asynchronous tasks. I want to implement a function to cancel the running task.
The official documentrevoke: Revoking tasks says that the "revoke(terminate=True)" method can be used. I tried it but it didn't work. Here are some ways I've tried:
...
task = AsyncResult("1e8fb3f3-4253-4bec-b71a-665ba5d23004")
print(task.state)
'STARTED'
task.revoke(terminate=True)
print(task.state)
'STARTED'
app.control.revoke("1e8fb3f3-4253-4bec-b71a-665ba5d23004", terminate=True)
print(task.state)
'STARTED'
And eventually it still executes to completion. Has anyone encountered a similar problem? Or is there another way to achieve my needs in celery? Any help would be greatly appreciated!