Send_picture_automatically/service_runner.py
Your Name aaf5f59b59 feat: 改进定时任务管理并更新配置
- 在service_runner.py中添加进程ID记录功能
- 增强stop_scheduler.py以同时处理scheduler.py和sendmsg.py进程
- 修改sendmsg.py增加重试机制
- 更新配置文件路径和执行时间
2025-08-15 19:45:46 +08:00

26 lines
838 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"
pid_file = Path(__file__).parent / "scheduler_pid.txt"
# 使用pythonw.exe在后台运行无窗口
pythonw_path = sys.executable.replace('python.exe', 'pythonw.exe')
process = subprocess.Popen([pythonw_path, str(script_path)],
cwd=str(Path(__file__).parent),
creationflags=subprocess.CREATE_NO_WINDOW)
# 保存进程ID到文件
with open(pid_file, 'w') as f:
f.write(str(process.pid))
print(f"定时任务已在后台启动进程ID: {process.pid}")
print(f"进程ID已保存到: {pid_file}")
if __name__ == "__main__":
run_in_background()