发布时间:2022-06-08 09:43:42 人气:15 作者:多测师
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相关知识,请关注多测师。https://www.e70w.com/xwzx/