- 在service_runner.py中添加进程ID记录功能 - 增强stop_scheduler.py以同时处理scheduler.py和sendmsg.py进程 - 修改sendmsg.py增加重试机制 - 更新配置文件路径和执行时间
26 lines
838 B
Python
26 lines
838 B
Python
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() |