diff --git a/base/plugin_common/plugin_manager.py b/base/plugin_common/plugin_manager.py index d614b1d..aba06d7 100644 --- a/base/plugin_common/plugin_manager.py +++ b/base/plugin_common/plugin_manager.py @@ -61,7 +61,8 @@ class PluginManager: # 热加载相关 self._watcher_thread: Optional[threading.Thread] = None self._watcher_stop_event = threading.Event() - self._watcher_interval = 2.0 + # 默认每 60 秒扫描一次插件目录,降低线上资源消耗 + self._watcher_interval = 60.0 self._module_file_state: Dict[str, Dict[str, float]] = {} self._watcher_lock = threading.RLock() @@ -132,9 +133,12 @@ class PluginManager: except Exception as e: self.LOG.error(f"自动注入 bot 到插件 {plugin.name} 失败: {e}") - def start_hot_reload_watcher(self, interval_seconds: float = 2.0): + def start_hot_reload_watcher(self, interval_seconds: float = 60.0): """ 启动插件目录变更监听线程(轮询) + + Args: + interval_seconds: 轮询间隔秒数,默认 60 秒 """ with self._watcher_lock: if self._watcher_thread and self._watcher_thread.is_alive(): diff --git a/robot.py b/robot.py index 807ced1..1d71191 100644 --- a/robot.py +++ b/robot.py @@ -98,7 +98,8 @@ class Robot: self.plugin_manager = PluginManager(plugin_dir=getattr(self.config, "plugin_dir", "plugins")) self.plugin_manager.set_system_context(self.system_context) self.plugins = self.plugin_manager.load_all_plugins() - self.plugin_manager.start_hot_reload_watcher(interval_seconds=2.0) + # 热加载改为低频扫描:每 60 秒检查一次插件文件变动 + self.plugin_manager.start_hot_reload_watcher(interval_seconds=60.0) # 加载插件 self.LOG.debug("插件系统初始化完成")