【发布时间】:2018-05-12 11:13:15
【问题描述】:
我想从 Python 脚本中启动和停止 celery 工作进程。我使用 Redis 作为代理和后端。
我发出一个 Popen 命令以从为工作人员安排任务的脚本中启动工作人员:
# start the celery deamon
cmd = 'celery worker '
cmd += '--app intertext.tasks '
cmd += '--loglevel critical'
subprocess.Popen(shlex.split(cmd))
所有步骤完成后,我想删除所有工作进程。我知道我可以执行ps -ef | grep celery | awk '{print $2}' | xargs kill -9 之类的操作,但这不会在 Windows 上运行。
杀死使用 Popen 打开的进程的最佳方法是什么(或从 Python 脚本中启动和停止 celery 守护进程的最佳方法)?
【问题讨论】:
-
如何记下通过
Popen打开的进程的pid? docs.python.org/3/library/subprocess.html#subprocess.Popen.pid -
@AliYılmaz 我怎样才能让它在 Windows 上也能工作?我正在阅读stackoverflow.com/questions/4789837/…