diff --git a/app/command.py b/app/command.py index b7017e25..9a260f21 100644 --- a/app/command.py +++ b/app/command.py @@ -181,6 +181,8 @@ class Command(metaclass=Singleton): """ self._event.set() self._thread.join() + if self._db: + self._db.close() def get_commands(self): """ diff --git a/app/core/plugin.py b/app/core/plugin.py index 2c94a817..0ff14907 100644 --- a/app/core/plugin.py +++ b/app/core/plugin.py @@ -83,6 +83,9 @@ class PluginManager(metaclass=Singleton): """ # 停止所有插件 for plugin in self._running_plugins.values(): + # 关闭数据库 + if hasattr(plugin, "close"): + plugin.close() # 关闭插件 if hasattr(plugin, "stop_service"): plugin.stop_service() diff --git a/app/db/systemconfig_oper.py b/app/db/systemconfig_oper.py index 64fcca0f..f4ef206f 100644 --- a/app/db/systemconfig_oper.py +++ b/app/db/systemconfig_oper.py @@ -56,3 +56,7 @@ class SystemConfigOper(DbOper, metaclass=Singleton): if not key: return self.__SYSTEMCONF return self.__SYSTEMCONF.get(key) + + def __del__(self): + if self._db: + self._db.close() diff --git a/app/helper/sites.cp311-win_amd64.pyd b/app/helper/sites.cp311-win_amd64.pyd index ef3ceea4..68995f57 100644 Binary files a/app/helper/sites.cp311-win_amd64.pyd and b/app/helper/sites.cp311-win_amd64.pyd differ diff --git a/app/helper/sites.cpython-311-aarch64-linux-gnu.so b/app/helper/sites.cpython-311-aarch64-linux-gnu.so index 2208ff1e..4d5b00d6 100644 Binary files a/app/helper/sites.cpython-311-aarch64-linux-gnu.so and b/app/helper/sites.cpython-311-aarch64-linux-gnu.so differ diff --git a/app/helper/sites.cpython-311-x86_64-linux-gnu.so b/app/helper/sites.cpython-311-x86_64-linux-gnu.so index b4e76cf7..f32adb93 100644 Binary files a/app/helper/sites.cpython-311-x86_64-linux-gnu.so and b/app/helper/sites.cpython-311-x86_64-linux-gnu.so differ diff --git a/app/plugins/__init__.py b/app/plugins/__init__.py index f4e244e1..928eb056 100644 --- a/app/plugins/__init__.py +++ b/app/plugins/__init__.py @@ -184,3 +184,10 @@ class _PluginBase(metaclass=ABCMeta): channel=channel, mtype=mtype, title=title, text=text, image=image, link=link, userid=userid )) + + def close(self): + """ + 关闭数据库连接 + """ + if self.db: + self.db.close() diff --git a/app/scheduler.py b/app/scheduler.py index 3962c0bc..4feac033 100644 --- a/app/scheduler.py +++ b/app/scheduler.py @@ -106,3 +106,5 @@ class Scheduler(metaclass=Singleton): """ if self._scheduler.running: self._scheduler.shutdown() + if self._db: + self._db.close()