python第三方工具cdiff、yapf、isort、supervisor

来源:互联网 发布:java数组和指针的区别 编辑:程序博客网 时间:2024/06/15 07:04

cdiff

比较工具

# 下载pip install cdiff# 结合其他diff工具使用diff -u a.txt b.txt | cdiffgit diff a.txt b.txt | cdiff

yapf

格式化代码工具,可以将不规范的代码格式化

# 下载pip install yapf# 将old.py中代码格式化之后,输出到new.py中yapf old.py > new.py# 直接修改old.py源文件,使用-i参数yapf -i old.py

isort

格式化python导入模块部分。python经常需要导入其他模块,但是导入模块的代码混乱不堪,使用isort可以美化这部分的代码

# 下载pip install isort# 格式化导入模块的代码isort -ls old.py

supervisor

进程管理工具,监听、启动、停止、重启一个或多个进程。自动重启进程服务。

# 下载pip install supervisor# 生成配置文件, 若无权限请使用root。这里的生成的配置文件位置和名字可自定义mkdir -p /etc/supervisor/conf.dcp /etc/supervisord.conf /etc/supervisor/supervisord.conf # 修改配置文件vim /etc/supervisor/supervisord.conf # 将[include]中的内容进行修改成如下配置,修改配置文件目录,并添加配置文件的后缀,定义为ini和conf[include]files = /etc/supervisor/conf.d/*.inifiles = /etc/supervisor/conf.d/*.conf# 保存退出

写一个配置文件的例子

# 写在生成配置文件目录下的conf.d目录,名字可自定义vim /etc/supervisor/conf.d/example.conf[program:example] # 必须与文件名相同,如这里是example# 以下命令,可以只使用前五行command=/usr/bin/python3 /root/test/test.py # 执行的命令autostart=true # 是否随着supervisord启动autorestart=true # 是否自动重启startsecs=5 # 被杀死后,5s后重启startretries=5 # 被杀死后,重启次数user=root # 执行的用户stdout_logfile=/root/test/logs/log.out # 标准输出日志文件stopasgroup=true # 默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程killasgroup=true # 默认为false,向进程组发送kill信号,包括子进程# 保存退出# 启动服务supervisord -c /etc/supervisor/supervisord.conf# 这样就启动了supervisord的服务,可以使用ps -aux | grep supervisord 查看是否有进程ps -aux | grep supervisord# 在启动进程之后,可以进入交互模式下进行管理进程supervisorctl# 首先会输出当前运行和终止的进程supervisor> help # 查看帮助supervisor> stop example # 停止example这个进程supervisor> start all # 开启配置目录下所有进程supervisor> restart example # 重启example这个进程supervisor> status # 查看所有进程状态supervisor> update # 更新进程服务# 也可以不进入交互模式管理进程,只需要在命令前加上supervisorctl即可supervisorctl restart all
原创粉丝点击