![图片[1]-python怎么设置每隔几秒执行脚本?-uusu优素-乐高,模型,3d打印,编程](http://uusucn.zbbe.cn/wp-content/uploads/2024/01/5ec37a5f2ed5b627.jpg)
python设置每隔几秒执行脚本的方法:
1、利用python死循环实现每10s执行一次脚本
#!/usr/bin/envpython
importos,time
#howtorunit?
#nohuppython-uexample.py>>/data/logs/example.log2>&1&
whileTrue:
os.system('command')//执行系统命令
time.sleep(10)//推迟执行、休眠
2、设置1-10s执行一次脚本
#!/usr/bin/envpython
importos,time,random
#howtorunit?
#nohuppython-uexample.py>>/data/logs/example.log2>&1&
whileTrue:
sleeptime=random.randint(0,10)//1-10随机数
os.system('command')
time.sleep(sleeptime)原文来自:https://www.py.cn © 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END

















































暂无评论内容