工作小笔记之python相关

/ 默认分类 / 没有评论 / 27浏览

# filter删除列表空元素

kk = ['[Atransactions: 315 errors: 0 average: 0.31 throught: 3.18 threads: 1', '']

kkk = list(filter(None,kk))


# gunicorn + flask

gunicorn -w 4 -b 127.0.0.1:4000
run:app -w 4是指预定义的工作进程数为4
-b 127.0.0.1:4000指绑定地址和端口
run是flask的启动python文件
app则是flask应用程序实例


# python 通过pid杀进程

import subprocess,sys,os,signal
processname = sys.argv[1]
zy = '{print $2}'
cmd = "ps -ef|grep -v grep|grep -v python3.7|grep {processname}|awk'{zy}'".format(processname=processname,zy=zy)
print(cmd)

p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
s = p.poll()
pout = p.stdout.readlines()

for line in pout:
line = int(line.strip().decode('utf-8'))
print(line) \n\r
os.kill(line,signal.SIGKILL)