python定时执行脚本实例
2017-08-29 20:01
330 查看
定时任务代码实例
#coding=utf-8 #这里需要引入三个模块 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): # enter用来安排某事件的发生时间,从现在起第n秒开始启动 schedule.enter(inc, 0, perform_command, (cmd, inc)) # 持续运行,直到计划时间队列变成空为止 schedule.run() print("ready to excute scrapt...") timming_exe("echo hello world", 10)
周期性执行实例
#coding=utf-8 import time, os, sched # 第一个参数确定任务的时间,返回从某个特定的时间到现在经历的秒数 # 第二个参数以某种人为的方式衡量时间 schedule = sched.scheduler(time.time, time.sleep) def perform_command(cmd, inc): # 安排inc秒后再次运行自己,即周期运行 schedule.enter(inc, 0, perform_command, (cmd, inc)) os.system(cmd) def timming_exe(cmd, inc = 60): # enter用来安排某事件的发生时间,从现在起第n秒开始启动 schedule.enter(inc, 0, perform_command, (cmd, inc)) # 持续运行,直到计划时间队列变成空为止 schedule.run() print("ready to excute scrapt...") timming_exe("echo hello world", 10)
反复执行实例
#coding=utf-8 # 以需要的时间间隔执行某个命令 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)
相关文章推荐
- python定时执行脚本实例
- MySQL定时执行脚本(计划任务)命令实例
- python编写定时执行脚本
- crontab 定时执行python脚本
- MySQL定时执行脚本(计划任务)命令实例
- windows下python设置定时任务(定时执行脚本)
- crontab 定时执行python脚本
- ubuntu定时执行python脚本
- MySQL定时执行脚本(计划任务)命令实例
- MySQL定时执行脚本(计划任务)命令实例
- c# 定时执行python脚本
- 定时执行Python脚本或模型
- windows创建定时任务执行python脚本
- Python脚本在crontab定时任务中无法运行,但是对应脚本手动执行成功
- 怎样在windows上定时执行python脚本
- Mac下定时执行python脚本&sh脚本
- linux下使用crontab定时执行python脚本
- MySQL定时执行脚本(计划任务)命令实例
- python脚本利用windows计划定时执行
- MySQL定时执行脚本(计划任务)实例