fix: 优化数据库连接关闭逻辑,确保资源正确释放并处理 Redis 关闭异常
This commit is contained in:
parent
5ba453fad7
commit
0903a00ed2
14
DB.py
14
DB.py
@ -293,10 +293,22 @@ class DBVidcon:
|
|||||||
"""批量执行完后手动提交。"""
|
"""批量执行完后手动提交。"""
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
@mysql_retry()
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
try:
|
||||||
|
if self.cursor:
|
||||||
self.cursor.close()
|
self.cursor.close()
|
||||||
|
finally:
|
||||||
|
if self.conn:
|
||||||
self.conn.close()
|
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)
|
@redis_retry(max_retries=3)
|
||||||
def get_proxy(self, region_code: str) -> str:
|
def get_proxy(self, region_code: str) -> str:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user