python 执行.py文件 周期运行

1 在当前文件创建helloworld.py文件

import os
os.system('C:python36python.exe helloworld.py ') # 指定路径 执行helloworld.py 文件

  

2 周期性执行helloworld.py 文件

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):
  schedule.enter(inc,0,perform_command,(cmd,inc))
  schedule.run()#持续运行,直到计划时间队列变成空为止
print('show time after 2 seconds:')
# timming_exe('echo %time%',1)
timming_exe('C:python36python.exe helloworld.py',2)

 执行效果

原文地址:https://www.cnblogs.com/zhangshijiezsj/p/15125190.html