zoukankan      html  css  js  c++  java
  • 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)
    

     执行效果

  • 相关阅读:
    python基本数据类型剖析
    常用正则表达式
    python_re模块
    迭代器模式
    状态模式
    备忘录模式
    asp.net 发送邮件
    建造者模式
    抽象工厂模式
    摸板模式与钩子
  • 原文地址:https://www.cnblogs.com/zhangshijiezsj/p/15125190.html
Copyright © 2011-2022 走看看