python设置每隔几秒执行脚本的方法:
在长葛等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站设计、成都网站设计 网站设计制作按需设计,公司网站建设,企业网站建设,品牌网站设计,全网营销推广,成都外贸网站制作,长葛网站建设费用合理。
1、利用python死循环实现每10s执行一次脚本
#!/usr/bin/env python import os,time #how to run it? #nohup python -u example.py >> /data/logs/example.log 2>&1 & while True: os.system('command')//执行系统命令 time.sleep(10)//推迟执行、休眠
2、设置1-10s执行一次脚本
#!/usr/bin/env python import os,time,random #how to run it? #nohup python -u example.py >> /data/logs/example.log 2>&1 & while True: sleeptime=random.randint(0, 10)//1-10随机数 os.system('command') time.sleep(sleeptime)
分享名称:创新互联Python教程:python怎么设置每隔几秒执行脚本?
文章地址:http://chengdu.cdxwcx.cn/article/cojoehj.html