feat: 跨平台进程保护机制 v5.3.0
- 新增 process_protection.py 模块 - 单实例保护: Windows命名Mutex / macOS+Linux fcntl文件锁 - 进程优先级提升: Windows SetPriorityClass / POSIX os.nice() - Windows PPL风格保护: SetErrorMode抑制错误弹窗 - POSIX信号保护: 忽略SIGHUP/SIGPIPE, 注册SIGTERM优雅关闭 - 看门狗监控: 后台线程监控父进程状态 - 关闭钩子系统: 进程退出时自动执行清理 - /protect 命令查看保护状态 - 更新 platform_utils.py 新增进程工具函数 - 集成到 cli_base.py 启动时自动初始化 - 更新 CHANGELOG.md / README.md 至 v5.3.0
This commit is contained in:
1 parent
a7f64cd797
commit
97cc2bb0f7
6 files changed
+808
-2
No files matched your search
@@ -11,6 +11,7 @@ from .constants import (
|
||||
)
|
||||
from .config import get_system_config, set_system_config, logger
|
||||
from .plugin_manager import LiuginManager
|
||||
from .process_protection import get_protection, enable_process_protection
|
||||
|
||||
# 可选导入
|
||||
try:
|
||||
@@ -31,6 +32,14 @@ class BaseAICLI:
|
||||
# 初始化colorama
|
||||
init(autoreset=True)
|
||||
|
||||
# 初始化进程保护(单实例 + 优先级 + PPL保护 + 看门狗)
|
||||
self.protection_results = enable_process_protection(
|
||||
priority_level="above_normal",
|
||||
watchdog=True,
|
||||
restart_on_crash=False,
|
||||
)
|
||||
self._protection = get_protection()
|
||||
|
||||
# 确保插件管理器使用正确的路径
|
||||
project_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
liugins_dir = os.path.join(project_dir, "plugins")
|
||||
@@ -114,6 +123,12 @@ class BaseAICLI:
|
||||
def cleanup_resources(self):
|
||||
"""清理资源,确保在程序退出时正确关闭所有资源"""
|
||||
print(f"{Fore.YELLOW}正在清理资源...{Style.RESET_ALL}")
|
||||
# 清理进程保护
|
||||
if hasattr(self, '_protection') and self._protection:
|
||||
try:
|
||||
self._protection.disable_all()
|
||||
except Exception:
|
||||
pass
|
||||
self._stop_clawli_monitor()
|
||||
if CLAWLI_SERVER_AVAILABLE and clawli_server:
|
||||
clawli_server.stop_server()
|
||||
|
||||
Reference in new issue
Block a user