新聞中心
python設置每隔幾秒執(zhí)行腳本的方法:

在長葛等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供網(wǎng)站設計、成都網(wǎng)站設計 網(wǎng)站設計制作按需設計,公司網(wǎng)站建設,企業(yè)網(wǎng)站建設,品牌網(wǎng)站設計,全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站制作,長葛網(wǎng)站建設費用合理。
1、利用python死循環(huán)實現(xiàn)每10s執(zhí)行一次腳本
#!/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')//執(zhí)行系統(tǒng)命令
time.sleep(10)//推遲執(zhí)行、休眠
2、設置1-10s執(zhí)行一次腳本
#!/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隨機數(shù)
os.system('command')
time.sleep(sleeptime)
文章題目:創(chuàng)新互聯(lián)Python教程:python怎么設置每隔幾秒執(zhí)行腳本?
當前網(wǎng)址:http://www.fisionsoft.com.cn/article/cojoehj.html


咨詢
建站咨詢
