定时任务代码实例
import time, os, sched
schedule = sched.scheduler(time.time, time.sleep)
def perform_command(cmd, inc):
os.system(cmd)
def timming_exe(cmd, inc = 60):
schedule.enter(inc, 0, perform_command, (cmd, inc))
schedule.run()
print("ready to excute scrapt...")
timming_exe("echo hello world", 10)
周期性执行实例
import time, os, sched
schedule = sched.scheduler(time.time, time.sleep)
def perform_command(cmd, inc):
schedule.enter(inc, 0, perform_command, (cmd, inc))
os.system(cmd)
def timming_exe(cmd, inc = 60):
schedule.enter(inc, 0, perform_command, (cmd, inc))
schedule.run()
print("ready to excute scrapt...")
timming_exe("echo hello world", 10)
反复执行实例
import time, os
def re_exe(cmd, inc = 60):
while True:
os.system(cmd);
time.sleep(inc)
print("ready to excute scrapt...")
re_exe("echo hello world", 10)