Send_picture_automatically/service_runner.py
teddy 546ca9dfe2 feat: 添加定时任务后台运行和停止功能
新增service_runner.py用于后台运行定时任务,使用pythonw.exe实现无窗口运行
新增stop_scheduler.py用于停止后台定时任务进程
调整scheduler.py中的任务执行时间
2025-06-24 17:49:10 +08:00

20 lines
591 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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