无限次重启该脚本

 

import os

for i in range(1, 10):
if i % 3 == 0:
print(i)
s = 'python %s' % (__file__)
os.system(s)
     os._exit(123)



ps -aux | grep python | grep -v grep |cut -c 9-15 | xargs kill -9




初始数据,查询数据库异常,无限次重启该脚本(2003, "Can't connect to MySQL server on 'rm-xx.mysql.rds.yun.com' (timed out)")20171206 09:59:13


except Exception as e:
s = '%s%s%s' % ('初始数据,查询数据库异常,无限次重启该脚本', e, time.strftime('%Y%m%d %H:%M:%S', time.localtime(time.time())))
print(s)
logging.warning(s)
cmd = 'python %s' % (__file__)
os.system(cmd)
os._exit(1024)



达到预期效果



posted @ 2017-12-05 19:34  papering  阅读(496)  评论(0编辑  收藏  举报