fix db session

This commit is contained in:
jxxghp 2023-09-09 20:56:37 +08:00
parent a7a0889867
commit 9b17d55ac0
8 changed files with 18 additions and 0 deletions

View File

@ -181,6 +181,8 @@ class Command(metaclass=Singleton):
"""
self._event.set()
self._thread.join()
if self._db:
self._db.close()
def get_commands(self):
"""

View File

@ -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()

View File

@ -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()

Binary file not shown.

View File

@ -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()

View File

@ -106,3 +106,5 @@ class Scheduler(metaclass=Singleton):
"""
if self._scheduler.running:
self._scheduler.shutdown()
if self._db:
self._db.close()