如何杀死所有 Celery 后台进程

发布于 2025-01-16 08:16:04 字数 387 浏览 2 评论 0原文

终止所有 celery 进程涉及到“ps”命令上的“grep”并对所有 PID 运行kill 命令。格雷平 ps 命令会显示 grep 命令的自身进程信息。为了跳过该 PID,'grep -v grep' 命令是管道式的,它在 'grep' 搜索键上执行 'not' 条件。 “awk”命令是 用于仅过滤第二个,“tr”命令将“awk”命令输出的结果从行转换为列。 管道“kill”命令不起作用,因此整个过程已设置为命令替换,即 '$()'。最后的重定向不是强制性的。它只是将整个输出抑制到后台。

kill -9 $(ps aux | grep celery | grep -v grep | awk '{print $2}' | tr '\n' ' ') > /dev/null 2>&1

Killing all celery processes involves 'grep'ing on 'ps' command and run kill command on all PID. Greping
on ps command results in showing up self process info of grep command. In order to skip that PID, 'grep
-v grep' command is piplined which executes 'not' condition on 'grep' search key. The 'awk' command is
used to filter only 2nd and 'tr' command translates result of 'awk' command output from rows to columns.
Piplining 'kill' command did not work and so the entire process has been set as command substitution, i.e.,
'$()'. The redirection at the end is not mandatory. Its only to supress the enitre output into background.

kill -9 $(ps aux | grep celery | grep -v grep | awk '{print $2}' | tr '\n' ' ') > /dev/null 2>&1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝咒 2025-01-23 08:16:04

除了终止 celery 进程的标准 unix 方法之外,Celery 还提供 API 来终止侦听特定代理的所有工作进程。

  1. 使用python来杀掉。您可以参考文档此处< /a> 或 此处。前者在内部调用后者的函数。

app.control.shutdown()

其中 app 是使用代理配置的 celery 应用实例。

  1. Celery 命令行界面也可以用于相同的目的。

celery -A app_name 控制关闭

Apart from the standard unix ways of killing celery processes, Celery also provides API to kill all the workers listening on a particular broker.

  1. To kill using python. You can refer to the docs here or here. Former calls the latter function internally.

app.control.shutdown()

where app is the celery app instance configured with the broker.

  1. Celery command line interface can also be used for the same.

celery -A app_name control shutdown

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文