Constantly monitor a program/process using Python

与世无争的帅哥 提交于 2019-12-03 12:59:18

There are many programs that can do this.

On Ubuntu there is upstart (installed by default)

Lots of people like http://supervisord.org/

monit as mentioned by @nathan

If you are looking for a python alternative there is a library that has just been released called circus which looks interesting.

And pretty much every linux distro probably has one of these built in.

The choice is really just down to which one you like better, but you would be far better off using one of these than writing it yourself.

Hope that helps

gimel

If you are willing to control the monitored program directly from python instead of using cron, have a look at the subprocess module :

The subprocess module allows you to spawn new processes,
connect to their input/output/error pipes, and obtain their return codes.

Check examples like track process status with python on SO for examples and references.

You could just use monit http://mmonit.com/monit/

It monitors processes and restarts them (and other things.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!