python进程管理工具supervisor使用实例
平时我们写个脚本,要放到后台执行去,我们怎么做呢?
代码如下:
nohup python example.py 2>&1 /dev/null &
用tumx或者screen? 但是用着可能都不爽,今天就看看python里面的一个进程管理工具supervisor:
官方说:Supervisor: A Process Control System
说白了他就是一个demon程序,他来帮助我们完成对我们想要托管的脚本也好程序也好,好好的照料;
1、安装
python的东西就是好安装,如果是centos系列,可以使用:
代码如下:
yum install supervisor
如果是debin系列的:
代码如下:
apt-get install supervisor
或者干脆点:
代码如下:
easy_install supervisor
pip install supervisor
2、创建配置文件
你可以使用自带的一个工具:echo_supervisord_conf
默认是在/etc下 创建,但需要你有root权限:
代码如下:
echo_supervisord_conf > /etc/supervisord.conf
当然也可以是其它目录,但需要在启动的时候指定(-c)
3、启动Supervisor
接下来我们来看看怎么启动supervisord 和 supervisorctl
首先找一个要托管的程序,比如/bin/date
代码如下:
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
保存,启动:
代码如下:
/usr/bin/supervisord -c /etc/supervisord.conf
发送信号:
肿么样,很爽吧,接下来,就可以自由发挥了。。。
http://supervisord.org/ 这是官网。
最后的最后,他还可以界面管理哦,这也为我们在界面进行进程管理提供了一种方法哦!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

To run Python code in Sublime Text, you need to install the Python plug-in first, then create a .py file and write the code, and finally press Ctrl B to run the code, and the output will be displayed in the console.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".
