Python process management tool supervisor uses instances, pythonsupervisor
We usually write a script and put it in the background for execution. What should we do?
Copy codeThe Code is as follows:
Nohup python example. py 2> & 1/dev/null &
Tumx or screen? However, it may not work well. Today, let's look at a process management tool supervisor in python:
Said: Supervisor: A Process Control System
To put it bluntly, He is a demon program. He can help us complete the script or program we want to host, and take good care of it;
1. Installation
Python is well installed. If it is a centos series, you can use:
Copy codeThe Code is as follows:
Yum install supervisor
For the debin series:
Copy codeThe Code is as follows:
Apt-get install supervisor
Or simply click:
Copy codeThe Code is as follows:
Easy_install supervisor
Pip install supervisor
2. Create a configuration file
You can use the built-in tool echo_supervisord_conf.
It is created under/etc by default, but you need to have the root permission:
Copy codeThe Code is as follows:
Echo_supervisord_conf>/etc/supervisord. conf
Of course, it can also be another directory, but it must be specified at startup (-c)
3. Start Supervisor
Next, let's take a look at how to start supervisord and supervisorctl.
First, find a program to host, such as/bin/date.
Copy codeThe Code is as follows:
Vim/etc/supervisord. conf
[Program: test]
Command = python/root/test_supervisor.py
Process_name = % (program_name) s
Stdout_logfile =/root/test. log
Stderr_logfile =/root/test. log
Save and start:
Copy codeThe Code is as follows:
/Usr/bin/supervisord-c/etc/supervisord. conf
Sending signal:
It's so cool. Next, you can play it freely...
Http://supervisord.org/This is the official website.
At last, he can manage the interface, which also provides a way for us to manage processes on the interface!
How can I determine and kill a time-out python process?
Supervisord is dedicated to this. This is very mature, and the Python and MongoDB processes on the server are managed by it. If supervisord does not meet your needs, for example, you need to manage processes in your own program, you can refer to supervisord code implementation. Simple: You can use docs.python.org/library/subprocess.htmlto implement a set of features.
How can I determine and kill a time-out python process?
Supervisord is dedicated to this. This is very mature, and the Python and MongoDB processes on the server are managed by it. If supervisord does not meet your needs, for example, you need to manage processes in your own program, you can refer to supervisord code implementation.