Skip to content

Commit 00c6125

Browse files
author
yuniszhang
committed
不通过is来判断是否绑定了内置连接池
1 parent d64b628 commit 00c6125

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

qcloud_cos/cos_client.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class CosS3Client(object):
229229

230230
__built_in_sessions = None # 内置的静态连接池,多个Client间共享使用
231231
__built_in_pid = 0
232+
__built_in_used = False
232233

233234
def __init__(self, conf, retry=1, session=None):
234235
"""初始化client对象
@@ -248,6 +249,7 @@ def __init__(self, conf, retry=1, session=None):
248249

249250
if session is None:
250251
self._session = CosS3Client.__built_in_sessions
252+
CosS3Client.__built_in_used = True
251253
logger.info("bound built-in connection pool success. maxsize=%d,%d" % (self._conf._pool_connections, self._conf._pool_maxsize))
252254
else:
253255
self._session = session
@@ -261,18 +263,13 @@ def set_built_in_connection_pool_max_size(self, PoolConnections, PoolMaxSize):
261263
and CosS3Client.__built_in_sessions.get_adapter('http://')._pool_maxsize == PoolMaxSize:
262264
return
263265

264-
# 判断之前是否绑定到内置连接池
265-
rebound = False
266-
if self._session and self._session is CosS3Client.__built_in_sessions:
267-
rebound = True
268-
269266
# 重新生成内置连接池
270267
CosS3Client.__built_in_sessions.close()
271268
CosS3Client.__built_in_sessions = self.generate_built_in_connection_pool(PoolConnections, PoolMaxSize)
272269
CosS3Client.__built_in_pid = os.getpid()
273270

274271
# 重新绑定到内置连接池
275-
if rebound:
272+
if CosS3Client.__built_in_used:
276273
self._session = CosS3Client.__built_in_sessions
277274
logger.info("rebound built-in connection pool success. maxsize=%d,%d" % (PoolConnections, PoolMaxSize))
278275

@@ -294,19 +291,14 @@ def handle_built_in_connection_pool_by_pid(self):
294291
with threading.Lock():
295292
if CosS3Client.__built_in_pid == os.getpid(): # 加锁后double check
296293
return
297-
298-
# 判断之前是否绑定到内置连接池
299-
rebound = False
300-
if self._session and self._session is CosS3Client.__built_in_sessions:
301-
rebound = True
302294

303295
# 重新生成内置连接池
304296
CosS3Client.__built_in_sessions.close()
305297
CosS3Client.__built_in_sessions = self.generate_built_in_connection_pool(self._conf._pool_connections, self._conf._pool_maxsize)
306298
CosS3Client.__built_in_pid = os.getpid()
307299

308300
# 重新绑定到内置连接池
309-
if rebound:
301+
if CosS3Client.__built_in_used:
310302
self._session = CosS3Client.__built_in_sessions
311303
logger.info("rebound built-in connection when new process. maxsize=%d,%d" % (self._conf._pool_connections, self._conf._pool_maxsize))
312304

0 commit comments

Comments
 (0)