From 0903a00ed2946419f93339e20adbd42663a0df92 Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Tue, 20 May 2025 21:39:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E8=BF=9E=E6=8E=A5=E5=85=B3=E9=97=AD=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E7=A1=AE=E4=BF=9D=E8=B5=84=E6=BA=90=E6=AD=A3=E7=A1=AE?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E5=B9=B6=E5=A4=84=E7=90=86=20Redis=20?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/DB.py b/DB.py index 2c3feda..ce339e1 100644 --- a/DB.py +++ b/DB.py @@ -293,10 +293,22 @@ class DBVidcon: """批量执行完后手动提交。""" self.conn.commit() - @mysql_retry() def close(self): - self.cursor.close() - self.conn.close() + try: + if self.cursor: + self.cursor.close() + finally: + if self.conn: + self.conn.close() + try: + if hasattr(self, "redis") and self.redis: + # redis-py ≥ 4.2 推荐直接调用 .close() + if hasattr(self.redis, "close"): + self.redis.close() + else: + self.redis.connection_pool.disconnect() + except Exception as e: + print("[Redis close error]", e) @redis_retry(max_retries=3) def get_proxy(self, region_code: str) -> str: