可以成功动态更换yolo模型并重启服务生效

This commit is contained in:
2025-09-12 18:28:43 +08:00
parent 4be7f7bf14
commit 206652d6bb
6 changed files with 499 additions and 123 deletions

View File

@ -3,6 +3,8 @@ from mysql.connector import Error
from .config import MYSQL_CONFIG
# 关键:声明类级别的连接池实例(必须有这一行!)
_connection_pool = None # 确保这一行存在,且拼写正确
class Database:
"""MySQL 连接池管理类"""
@ -41,6 +43,18 @@ class Database:
except Error as e:
raise Exception(f"MySQL 连接关闭失败: {str(e)}") from e
@classmethod
def close_all_connections(cls):
"""清理连接池(服务重启前调用)"""
try:
# 先检查属性是否存在,再判断是否有值
if hasattr(cls, "_connection_pool") and cls._connection_pool:
cls._connection_pool = None # 重置连接池
print("[Database] 连接池已重置,旧连接将被自动清理")
else:
print("[Database] 连接池未初始化或已重置,无需操作")
except Exception as e:
print(f"[Database] 重置连接池失败: {str(e)}")
# 暴露数据库操作工具
db = Database()