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

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


咨詢
建站咨詢
