supervisord 管理多进程程序如 pyspider 时的合适配置

现在的工程中,有一部分是用 pyspider 来抓取数据的,使用 supervisord 来管理它的进程。在使用过程中,遇到一个奇怪的问题:用supervisorctl stop pyspider之后,pyspider 并未全部停止,而是留下了三四个进程在系统中。

查阅官方手册,在 [program:x] Section Settings 中找到了名为 stopasgroup 的选项,解释如下:

If true, the flag causes supervisor to send the stop signal to the whole process group and implies killasgroup is true. This is useful for programs, such as Flask in debug mode, that do not propagate stop signals to their children, leaving them orphaned.

在 [program:pyspider] 小节,开启这个选项。如:

[program:pyspider]
command=/home/oott123/pyspider/run.py
autorestart=true
startsecs=2
user=oott123
directory=/home/oott123/pyspider/
redirect_stderr=true
stopasgroup=true
environment=WEBUI_HOST="127.0.0.1",WEBUI_PORT="5033"

然后重启 supervisord ,再测试停止 pyspider 的服务,它就不会残留那几个进程了。

评论

还没有评论。

发表评论

发表评论代表你授权本网站存储并在必要情况下使用你输入的邮箱地址、连接本站服务器使用的 IP 地址和用户代理字符串 (User Agent) 用于发送评论回复邮件,以及将上述信息分享给 Libravatar Akismet,用于显示头像和反垃圾。