新增service_runner.py用于后台运行定时任务,使用pythonw.exe实现无窗口运行 新增stop_scheduler.py用于停止后台定时任务进程 调整scheduler.py中的任务执行时间
20 lines
591 B
Python
20 lines
591 B
Python
import subprocess
|
||
import sys
|
||
import os
|
||
from pathlib import Path
|
||
|
||
def run_in_background():
|
||
"""在后台运行定时任务"""
|
||
script_path = Path(__file__).parent / "scheduler.py"
|
||
|
||
# 使用pythonw.exe在后台运行(无窗口)
|
||
pythonw_path = sys.executable.replace('python.exe', 'pythonw.exe')
|
||
|
||
subprocess.Popen([pythonw_path, str(script_path)],
|
||
cwd=str(Path(__file__).parent),
|
||
creationflags=subprocess.CREATE_NO_WINDOW)
|
||
|
||
print("定时任务已在后台启动")
|
||
|
||
if __name__ == "__main__":
|
||
run_in_background() |