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()