my_scheduler.py 598 B

1234567891011121314151617
  1. import schedule
  2. import time
  3. import subprocess
  4. def run_in_new_window():
  5. script_path = r"D:\drug\pdd1\pdd_new.py"
  6. # 关键修改:在命令末尾添加 || exit,失败时自动关闭窗口
  7. cmd = f'start cmd /k "python {script_path} || exit"'
  8. subprocess.Popen(cmd, shell=True)
  9. print(f"[{time.ctime()}] 已启动新窗口执行任务(失败将自动关闭)")
  10. # 每10分钟执行一次
  11. schedule.every(1).minutes.do(run_in_new_window)
  12. print("调度器已启动,每10分钟会弹出一个新cmd窗口运行pdd_new.py")
  13. while True:
  14. schedule.run_pending()
  15. time.sleep(1)