From 9370c2f2ec4792d5104c1d75e325980efb045e48 Mon Sep 17 00:00:00 2001 From: 16337 <1633794139@qq.com> Date: Thu, 26 Mar 2026 09:08:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=A5=E6=8A=A5=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=20MySQL=20=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=96=AD=E5=BC=80=E9=97=AE=E9=A2=98=EF=BC=88BrokenPipe?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加 pool_recycle=1800 和 pool_pre_ping=True, 防止 MySQL 长时间空闲后连接被服务端关闭导致 BrokenPipeError。 --- app/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models.py b/app/models.py index be0af02..a7b1c15 100644 --- a/app/models.py +++ b/app/models.py @@ -524,7 +524,12 @@ def get_engine(): connect_args=connect_args, ) else: - _engine = create_engine(db_url, echo=settings.app.debug) + _engine = create_engine( + db_url, + echo=settings.app.debug, + pool_recycle=1800, + pool_pre_ping=True, + ) return _engine