如何在 运行 期间撤销任务

How to revoke the task while running

当我发送任务并尝试撤销时:

app=Celery()
app.control.revoke(task.id)
#or
app.control.revoke(task.id, terminate=True)

我收到那个错误:

[2019-09-05 05:27:50,110: ERROR/MainProcess] pidbox command error: NotImplementedError("<class 'celery.concurrency.gevent.TaskPool'> does not implement kill_job",)

我正在使用 gevent。

celery -A MyApp worker -l info -P gevent

怎么了?

gevent 并发不允许终止作业。 Pre-fork 确实允许它,因为它就像杀死工作进程一样简单 运行 您想要终止的任务,线程也是如此。

关于这个有一个问题,提出了解决方案 - https://github.com/celery/celery/issues/4019 - 但没有人提出 PR。