新增service_runner.py用于后台运行定时任务,使用pythonw.exe实现无窗口运行 新增stop_scheduler.py用于停止后台定时任务进程 调整scheduler.py中的任务执行时间
25 lines
825 B
Python
25 lines
825 B
Python
import subprocess
|
|
import sys
|
|
import os
|
|
|
|
def stop_scheduler():
|
|
"""停止定时任务进程"""
|
|
try:
|
|
# 查找并结束scheduler.py进程
|
|
result = subprocess.run(['tasklist', '/FI', 'IMAGENAME eq pythonw.exe', '/FO', 'CSV'],
|
|
capture_output=True, text=True)
|
|
|
|
if 'scheduler.py' in result.stdout:
|
|
# 结束包含scheduler.py的pythonw进程
|
|
subprocess.run(['taskkill', '/F', '/IM', 'pythonw.exe'], check=True)
|
|
print("定时任务已停止")
|
|
else:
|
|
print("未找到运行中的定时任务")
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"停止进程时出错: {e}")
|
|
except Exception as e:
|
|
print(f"发生错误: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
stop_scheduler() |