import subprocess as sb
import time,sys,datetime
count = 1
while True:
try:
count += 1
res = sb.getoutput("ps -ef|grep python3") #查看是否还在运行中,
if "zdjy" in res:#判断
print('运行正常',datetime.datetime.now())
# res = res.split("\n")
# for i in res:
# if "zdjy" in i:
# print(i)
# res2 = i.split(" ")[1]
# num = res2.strip()
else:
print('找不到进程,重新启动',datetime.datetime.now())
sb.getoutput("nohup python3 zdjy\(1\).py &")
time.sleep(10)
print(count)
except:
pass
posted on 2020-04-04 22:25  专注于区块链开发  阅读(1119)  评论(3编辑  收藏  举报