"Python" uses supervisor to manage the Python process

Source: Internet
Author: User

1. Description of the problem

Requires a Python service program to run in the background, not to let the process be killed, even if killed to be able to automatically restart in a timely manner. For example, there is a Python program: test.py, which runs the program by command: Python test.py, but it is interrupted by a command line interrupt. So we need a way to keep the program running in the background.


2. Workaround

I used to always use the command: Nohup python test.py & to keep it running uninterrupted in the background, but that's not guaranteed to run all the time.

The following describes the process of using supervisor to manage Python, keeping it running uninterrupted in the background.


(1) Installation Supervisor

On the command line input: sudo apt-get install supervisor for installation supervisor

To test whether the installation was successful, enter at the command line: Supervis and then press the TAB key to see if it can complete the command: supervisor, if the installation is successful


(2) Configuring the supervisord.conf file

Locate the supervisord.conf configuration file, usually under the/etc/directory, or under the/etc/supervisor/directory, open the file with root privileges: sudo vim supervisord.conf, otherwise it cannot be modified.

Add the following lines at the end of the file:

[Program:myprogram]

command=python/home/myname/test.py

Autostart=true

Autorestart=ture

Stdout_logfile=/home/myname/test.log


Note: the first line of MyProgram a name to indicate your project.

The second line of python/home/myname/test.py shows you the command to run the program

The third line indicates auto-start, and if the value is false, it does not start automatically

Row Four indicates an automatic restart, and a value of false indicates that it does not restart automatically

Finally, the program prints out the information that is recorded in the Test.log file, which is the log file


(3) using Supervisor

After the configuration is complete, the command line input: sudo supervisord is ok.

You can kill the process of your program and then look and see it automatically restarts without worrying about being killed.


Well, I hope it will be helpful to everyone.

--------------------------------------------------------------------------------------------------------------- --------------------------



"Python" uses supervisor to manage the Python process

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.