update pay function
This commit is contained in:
40
app_vx.py
40
app_vx.py
@@ -161,29 +161,36 @@ class ClickHouseConnectionPool:
|
||||
|
||||
# 初始化核心连接(延迟初始化,首次使用时创建)
|
||||
self._initialized = False
|
||||
# 清理线程也延迟启动(避免 fork 前启动线程导致问题)
|
||||
self._cleanup_thread_started = False
|
||||
logger.info(f"ClickHouse 连接池配置完成: pool_size={pool_size}, max_overflow={max_overflow}, "
|
||||
f"max_lifetime={max_connection_lifetime}s")
|
||||
|
||||
# 启动后台清理线程
|
||||
self._start_cleanup_thread()
|
||||
|
||||
# 注册退出时清理
|
||||
atexit.register(self.close_all)
|
||||
|
||||
def _start_cleanup_thread(self):
|
||||
"""启动后台清理线程"""
|
||||
def cleanup_worker():
|
||||
while not self._cleanup_stop_event.wait(self.cleanup_interval):
|
||||
if self._closed:
|
||||
break
|
||||
try:
|
||||
self._cleanup_expired_connections()
|
||||
except Exception as e:
|
||||
logger.error(f"清理连接时出错: {e}")
|
||||
"""启动后台清理线程(延迟启动,首次使用连接池时调用)"""
|
||||
if self._cleanup_thread_started or self._closed:
|
||||
return
|
||||
|
||||
self._cleanup_thread = _threading.Thread(target=cleanup_worker, daemon=True)
|
||||
self._cleanup_thread.start()
|
||||
logger.debug("后台清理线程已启动")
|
||||
with self._lock:
|
||||
if self._cleanup_thread_started or self._closed:
|
||||
return
|
||||
|
||||
def cleanup_worker():
|
||||
while not self._cleanup_stop_event.wait(self.cleanup_interval):
|
||||
if self._closed:
|
||||
break
|
||||
try:
|
||||
self._cleanup_expired_connections()
|
||||
except Exception as e:
|
||||
logger.error(f"清理连接时出错: {e}")
|
||||
|
||||
self._cleanup_thread = _threading.Thread(target=cleanup_worker, daemon=True, name="CH-Pool-Cleanup")
|
||||
self._cleanup_thread.start()
|
||||
self._cleanup_thread_started = True
|
||||
logger.debug("后台清理线程已启动")
|
||||
|
||||
def _cleanup_expired_connections(self):
|
||||
"""清理过期连接"""
|
||||
@@ -241,6 +248,9 @@ class ClickHouseConnectionPool:
|
||||
if self._initialized:
|
||||
return
|
||||
|
||||
# 启动清理线程(延迟到首次使用时启动)
|
||||
self._start_cleanup_thread()
|
||||
|
||||
# 只预创建 1 个连接,其余按需创建
|
||||
init_count = min(1, self.pool_size)
|
||||
for i in range(init_count):
|
||||
|
||||
Reference in New Issue
Block a user