python定时执行脚本实例
生活随笔
收集整理的這篇文章主要介紹了
python定时执行脚本实例
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
定時任務代碼實例
#! /usr/bin/env python3 #coding=utf-8 #引入time, os, sched,這三個是必備的 import time, os, sched # time.time 參數返回從某個特定的時間到現在經歷的秒數 # time.sleep 參數衡量的時間 schedule = sched.scheduler(time.time, time.sleep) def perform_command(cmd, inc): os.system(cmd) def timming_exe(cmd, inc =默認秒數周期 可等于 60 或者其他自定義即可 具體效果自己嘗試): #enter 設置從第幾秒開始運行schedule.enter(inc, 0, perform_command, (cmd, inc)) # 運行到結束schedule.run() print(" 這里寫你的調試信息 ") timming_exe("echo %time%", 間隔的秒數)周期性執行實例
#! /usr/bin/env python3 #coding=utf-8 #引入time, os, sched,這三個是必備的 import time, os, sched # time.time 參數返回從某個特定的時間到現在經歷的秒數 # time.sleep 參數衡量的時間 schedule = sched.scheduler(time.time, time.sleep) def perform_command(cmd, inc): # enter 計劃多少秒后,再次啟動自己并進行運行 schedule.enter(inc, 0, perform_command, (cmd, inc)) os.system(cmd) def timming_exe(cmd, inc = 默認秒數周期): # enter從現在起第n秒開始運行schedule.enter(inc, 0, perform_command, (cmd, inc)) #運行結束schedule.run() print(" 這里寫你的調試信息 ") timming_exe("echo %time%", 間隔的秒數)反復執行實例
#! /usr/bin/env python3 #coding=utf-8 #引入time, os # 設置指定的時間,間隔多少后再次執行命令 import time, os def re_exe(cmd, inc = 默認秒數周期): while True: os.system(cmd); time.sleep(inc) re_exe("echo %time%", 默認秒單次)總結
以上是生活随笔為你收集整理的python定时执行脚本实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mat分析dump分析_MAT从入门到精
- 下一篇: python正则匹配找到所有的浮点数_P