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

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


咨詢(xún)
建站咨詢(xún)
