场景:有时候jupyter进程会自动断开,我们使用这个程序来监听并重启jupyter。
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
参考的博主大神:https://www.cnblogs.com/hushuning/p/12634728.html