import schedule #定时模块
import time
import subprocess
def run_scripts ():
subprocess.run([“python”,“py文件路径”])
schedule.every().day.at(“12:05:03”).do(run_scripts)
while True:
schedule.run_scripts()
time.sleep (5)
此博客给出Python代码示例,利用schedule定时模块和subprocess库,实现每天12:05:03定时执行指定py文件的功能,代码包含函数定义和循环执行逻辑。
import schedule #定时模块
import time
import subprocess
def run_scripts ():
subprocess.run([“python”,“py文件路径”])
schedule.every().day.at(“12:05:03”).do(run_scripts)
while True:
schedule.run_scripts()
time.sleep (5)
1452
5039
1227