fix WEB页面活动时无法正常停止服务的问题
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import secrets
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
from typing import List, Optional
|
||||
|
||||
@ -9,6 +10,9 @@ from app.utils.system import SystemUtils
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""
|
||||
系统配置类
|
||||
"""
|
||||
# 项目名称
|
||||
PROJECT_NAME = "MoviePilot"
|
||||
# API路径
|
||||
@ -425,7 +429,31 @@ class Settings(BaseSettings):
|
||||
case_sensitive = True
|
||||
|
||||
|
||||
class GlobalVar(object):
|
||||
"""
|
||||
全局标识
|
||||
"""
|
||||
# 系统停止事件
|
||||
STOP_EVENT: threading.Event = threading.Event()
|
||||
|
||||
def stop_system(self):
|
||||
"""
|
||||
停止系统
|
||||
"""
|
||||
self.STOP_EVENT.set()
|
||||
|
||||
def is_system_stopped(self):
|
||||
"""
|
||||
是否停止
|
||||
"""
|
||||
return self.STOP_EVENT.is_set()
|
||||
|
||||
|
||||
# 实例化配置
|
||||
settings = Settings(
|
||||
_env_file=Settings().CONFIG_PATH / "app.env",
|
||||
_env_file_encoding="utf-8"
|
||||
)
|
||||
|
||||
# 全局标识
|
||||
global_vars = GlobalVar()
|
||||
|
@ -51,6 +51,7 @@ class ModuleManager(metaclass=Singleton):
|
||||
"""
|
||||
停止所有模块
|
||||
"""
|
||||
logger.info("正在停止所有模块...")
|
||||
for module_id, module in self._running_modules.items():
|
||||
if hasattr(module, "stop"):
|
||||
try:
|
||||
@ -58,6 +59,7 @@ class ModuleManager(metaclass=Singleton):
|
||||
logger.info(f"Moudle Stoped:{module_id}")
|
||||
except Exception as err:
|
||||
logger.error(f"Stop Moudle Error:{module_id},{str(err)} - {traceback.format_exc()}", exc_info=True)
|
||||
logger.info("模块停止完成")
|
||||
|
||||
def reload(self):
|
||||
"""
|
||||
|
@ -187,6 +187,7 @@ class PluginManager(metaclass=Singleton):
|
||||
:param pid: 插件ID,为空停止所有插件
|
||||
"""
|
||||
# 停止插件
|
||||
logger.info("正在停止所有插件...")
|
||||
for plugin_id, plugin in self._running_plugins.items():
|
||||
if pid and plugin_id != pid:
|
||||
continue
|
||||
@ -202,6 +203,7 @@ class PluginManager(metaclass=Singleton):
|
||||
# 清空
|
||||
self._plugins = {}
|
||||
self._running_plugins = {}
|
||||
logger.info("插件停止完成")
|
||||
|
||||
def __start_monitor(self):
|
||||
"""
|
||||
@ -219,9 +221,10 @@ class PluginManager(metaclass=Singleton):
|
||||
"""
|
||||
# 停止监测
|
||||
if self._observer:
|
||||
logger.info("正在停止监测插件文件修改...")
|
||||
logger.info("正在停止插件文件修改监测...")
|
||||
self._observer.stop()
|
||||
self._observer.join()
|
||||
logger.info("插件文件修改监测停止完成")
|
||||
|
||||
@staticmethod
|
||||
def __stop_plugin(plugin: Any):
|
||||
|
Reference in New Issue
Block a user