Python 如何停止芹菜工人进程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29306337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:21:56  来源:igfitidea点击:

How to stop celery worker process

pythondjangoamazon-ec2celery

提问by user61629

I have a Django project on an Ubuntu EC2 node, which I have been using to set up an asynchronous using Celery.

我在 Ubuntu EC2 节点上有一个 Django 项目,我一直在使用它来设置异步,使用Celery.

I am following thisalong with the docs.

我正在关注这个和文档。

I've been able to get a basic task working at the command line, using:

我已经能够在命令行上完成一项基本任务,使用:

(env1)ubuntu@ip-172-31-22-65:~/projects/tp$ celery --app=myproject.celery:app worker --loglevel=INFO

To start a worker. I have since made some changes to the Python, but realized that I need to restart a worker.

开始一个工人。此后我对 Python 进行了一些更改,但意识到我需要重新启动一个工作程序。

From the command line, I've tried:

从命令行,我试过:

 ps auxww | grep 'celery worker' | awk '{print }' | xargs kill -9

But I can see that the worker is still running.

但我可以看到工人仍在运行。

How can I kill it?

我怎样才能杀死它?

edit:

编辑:

(env1)ubuntu@ip-172-31-22-65:~/projects/tp$ sudo ps auxww | grep celeryd | grep -v "grep" | awk '{print }' | sudo xargs kill -HUP
kill: invalid argument H

Usage:
 kill [options] <pid> [...]

Options:
 <pid> [...]            send signal to every <pid> listed
 -<signal>, -s, --signal <signal>
                        specify the <signal> to be sent
 -l, --list=[<signal>]  list all signal names, or convert one to a name
 -L, --table            list all signal names in a nice table

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see kill(1).

edit 2:

编辑2:

(env1)ubuntu@ip-172-31-22-65:~/projects/tp$ ps aux|grep celery
ubuntu    9756  0.0  3.4 100868 35508 pts/6    S+   15:49   0:07 /home/ubuntu/.virtualenvs/env1/bin/python3.4 /home/ubuntu/.virtualenvs/env1/bin/celery --app=tp.celery:app worker --loglevel=INFO
ubuntu    9760  0.0  3.9 255840 39852 pts/6    S+   15:49   0:05 /home/ubuntu/.virtualenvs/env1/bin/python3.4 /home/ubuntu/.virtualenvs/env1/bin/celery --app=tp.celery:app worker --loglevel=INFO
ubuntu   12760  0.0  0.0  10464   932 pts/7    S+   19:04   0:00 grep --color=auto celery

采纳答案by itzMEonTV

Try this in terminal

在终端试试这个

ps aux|grep 'celery worker'

You will see like this

你会看到这样

username  29042  0.0  0.6  23216 14356 pts/1    S+   00:18   0:01 /bin/celery worker ...

Then kill process id by

然后杀死进程ID

sudo kill -9 process_id # here 29042

If you have multiple processes, then you have to kill all process id using above killcommmand

如果您有多个进程,则必须使用上述命令kill终止所有进程 ID

sudo kill -9 id1 id2 id3 ...

From the celery doc

来自芹菜文档

ps auxww | grep 'celery worker' | awk '{print }' | xargs kill -9

OR if you are running celeryd

或者如果你正在跑步 celeryd

ps auxww | grep celeryd | awk '{print }' | xargs kill -9

Note

笔记

If you are running celeryin supervisor, even though kill the process, it automatically restarts(if autorestart=Truein supervisor script).

如果你正在运行celerysupervisor,即使杀的过程中,它会自动重新启动(如果autorestart=True在主管脚本)。

回答by alan_wang

pkill -f "celery worker"

easy to kill process by string patterns

通过字符串模式轻松杀死进程

回答by Paulo Peres Junior

celery -A proj control shutdown

celery -A proj control shutdown

Edited, incremeting a litte bit.

编辑,增加一点点。

You should use this command from the root of your project, the "proj" is the name of your project, for instance if your Django project is called DjangoApp the command should look like this

您应该从项目的根目录使用此命令,“proj”是您的项目名称,例如,如果您的 Django 项目名为 DjangoApp,则该命令应如下所示

celery -a DjangApp control shutdown

celery -a DjangApp control shutdown

this should/will stop your celery worker from the project

这应该/将阻止您的芹菜工人参与该项目

回答by walter

ps auxww | grep 'celery worker' | grep -v " grep " | awk '{print }' | xargs kill -9

this one is very similar to one presented before but improved because avoid the error that shows when attempt to kill the grep process..

这个与之前介绍的非常相似,但有所改进,因为避免了在尝试终止 grep 进程时显示的错误..