@@ -229,7 +229,6 @@ class CosS3Client(object):
229
229
230
230
__built_in_sessions = None # 内置的静态连接池,多个Client间共享使用
231
231
__built_in_pid = 0
232
- __built_in_used = False
233
232
234
233
def __init__ (self , conf , retry = 1 , session = None ):
235
234
"""初始化client对象
@@ -241,37 +240,19 @@ def __init__(self, conf, retry=1, session=None):
241
240
self ._conf = conf
242
241
self ._retry = retry # 重试的次数,分片上传时可适当增大
243
242
244
- if not CosS3Client .__built_in_sessions :
245
- with threading .Lock ():
246
- if not CosS3Client .__built_in_sessions : # 加锁后double check
247
- CosS3Client .__built_in_sessions = self .generate_built_in_connection_pool (self ._conf ._pool_connections , self ._conf ._pool_maxsize )
248
- CosS3Client .__built_in_pid = os .getpid ()
249
-
250
243
if session is None :
244
+ if not CosS3Client .__built_in_sessions :
245
+ with threading .Lock ():
246
+ if not CosS3Client .__built_in_sessions : # 加锁后double check
247
+ CosS3Client .__built_in_sessions = self .generate_built_in_connection_pool (self ._conf ._pool_connections , self ._conf ._pool_maxsize )
248
+ CosS3Client .__built_in_pid = os .getpid ()
249
+
251
250
self ._session = CosS3Client .__built_in_sessions
252
- CosS3Client . __built_in_used = True
251
+ self . _use_built_in_pool = True
253
252
logger .info ("bound built-in connection pool when new client. maxsize=%d,%d" % (self ._conf ._pool_connections , self ._conf ._pool_maxsize ))
254
253
else :
255
254
self ._session = session
256
-
257
- def set_built_in_connection_pool_max_size (self , PoolConnections , PoolMaxSize ):
258
- """设置SDK内置的连接池的连接大小,并且重新绑定到client中"""
259
- if not CosS3Client .__built_in_sessions :
260
- return
261
-
262
- if CosS3Client .__built_in_sessions .get_adapter ('http://' )._pool_connections == PoolConnections \
263
- and CosS3Client .__built_in_sessions .get_adapter ('http://' )._pool_maxsize == PoolMaxSize :
264
- return
265
-
266
- # 重新生成内置连接池
267
- CosS3Client .__built_in_sessions .close ()
268
- CosS3Client .__built_in_sessions = self .generate_built_in_connection_pool (PoolConnections , PoolMaxSize )
269
- CosS3Client .__built_in_pid = os .getpid ()
270
-
271
- # 重新绑定到内置连接池
272
- if CosS3Client .__built_in_used :
273
- self ._session = CosS3Client .__built_in_sessions
274
- logger .info ("bound built-in connection pool when new config. maxsize=%d,%d" % (PoolConnections , PoolMaxSize ))
255
+ self ._use_built_in_pool = False
275
256
276
257
def generate_built_in_connection_pool (self , PoolConnections , PoolMaxSize ):
277
258
"""生成SDK内置的连接池,此连接池是client间共用的"""
@@ -284,6 +265,9 @@ def generate_built_in_connection_pool(self, PoolConnections, PoolMaxSize):
284
265
def handle_built_in_connection_pool_by_pid (self ):
285
266
if not CosS3Client .__built_in_sessions :
286
267
return
268
+
269
+ if not self ._use_built_in_pool :
270
+ return
287
271
288
272
if CosS3Client .__built_in_pid == os .getpid ():
289
273
return
@@ -298,9 +282,8 @@ def handle_built_in_connection_pool_by_pid(self):
298
282
CosS3Client .__built_in_pid = os .getpid ()
299
283
300
284
# 重新绑定到内置连接池
301
- if CosS3Client .__built_in_used :
302
- self ._session = CosS3Client .__built_in_sessions
303
- logger .info ("bound built-in connection pool when new processor. maxsize=%d,%d" % (self ._conf ._pool_connections , self ._conf ._pool_maxsize ))
285
+ self ._session = CosS3Client .__built_in_sessions
286
+ logger .info ("bound built-in connection pool when new processor. maxsize=%d,%d" % (self ._conf ._pool_connections , self ._conf ._pool_maxsize ))
304
287
305
288
def get_conf (self ):
306
289
"""获取配置"""
0 commit comments