python 执行.py文件 周期运行

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

import os
os.system('C:\python36\python.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:\python36\python.exe helloworld.py',2)

 执行效果

 

posted @ 2021-08-10 17:57  睁yan-ii  阅读(315)  评论(0编辑  收藏  举报