54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
import subprocess
|
|
import schedule
|
|
import time
|
|
from datetime import datetime
|
|
|
|
# 定义要启动的文件
|
|
files_to_run = ['专享策略20_o3mini.py']
|
|
|
|
|
|
def run_scripts():
|
|
print("启动程序...")
|
|
for file in files_to_run:
|
|
time.sleep(1)
|
|
# 使用subprocess模块运行命令
|
|
subprocess.Popen(['start', 'cmd', '/k', 'python', file], shell=True)
|
|
print(file)
|
|
print(datetime.now(),'程序重新启动完成,等待明天关闭重启')
|
|
|
|
|
|
def close_scripts():
|
|
print("关闭程序...")
|
|
# 通过创建一个包含关闭指定窗口命令的批处理文件来关闭CMD窗口
|
|
def close_specific_cmd_window(cmd_window_title):
|
|
with open("close_cmd_window.bat", "w") as batch_file:
|
|
batch_file.write(f'@echo off\nfor /f "tokens=2 delims=," %%a in (\'tasklist /v /fo csv ^| findstr /i "{cmd_window_title}"\') do taskkill /pid %%~a')
|
|
|
|
# 运行批处理文件
|
|
subprocess.run("close_cmd_window.bat", shell=True)
|
|
|
|
|
|
# 循环关闭所有脚本对应的CMD窗口
|
|
for title in files_to_run:
|
|
close_specific_cmd_window(title)
|
|
print(datetime.now(),'已关闭程序,等待重新运行程序')
|
|
|
|
|
|
|
|
# 设置定时任务,关闭程序
|
|
schedule.every().day.at("15:20").do(close_scripts)
|
|
schedule.every().day.at("02:45").do(close_scripts)
|
|
|
|
# 设置定时任务,启动程序
|
|
schedule.every().day.at("08:55").do(run_scripts)
|
|
schedule.every().day.at("20:55").do(run_scripts)
|
|
|
|
|
|
|
|
# 保持脚本运行,等待定时任务触发
|
|
#zzg_quant
|
|
while True:
|
|
schedule.run_pending()
|
|
time.sleep(1)
|
|
#zzg_quant
|