@@ -229,7 +229,6 @@ class CosS3Client(object):
229229
230230 __built_in_sessions = None # 内置的静态连接池,多个Client间共享使用
231231 __built_in_pid = 0
232- __built_in_used = False
233232
234233 def __init__ (self , conf , retry = 1 , session = None ):
235234 """初始化client对象
@@ -241,37 +240,19 @@ def __init__(self, conf, retry=1, session=None):
241240 self ._conf = conf
242241 self ._retry = retry # 重试的次数,分片上传时可适当增大
243242
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-
250243 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+
251250 self ._session = CosS3Client .__built_in_sessions
252- CosS3Client . __built_in_used = True
251+ self . _use_built_in_pool = True
253252 logger .info ("bound built-in connection pool when new client. maxsize=%d,%d" % (self ._conf ._pool_connections , self ._conf ._pool_maxsize ))
254253 else :
255254 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
275256
276257 def generate_built_in_connection_pool (self , PoolConnections , PoolMaxSize ):
277258 """生成SDK内置的连接池,此连接池是client间共用的"""
@@ -284,6 +265,9 @@ def generate_built_in_connection_pool(self, PoolConnections, PoolMaxSize):
284265 def handle_built_in_connection_pool_by_pid (self ):
285266 if not CosS3Client .__built_in_sessions :
286267 return
268+
269+ if not self ._use_built_in_pool :
270+ return
287271
288272 if CosS3Client .__built_in_pid == os .getpid ():
289273 return
@@ -298,9 +282,8 @@ def handle_built_in_connection_pool_by_pid(self):
298282 CosS3Client .__built_in_pid = os .getpid ()
299283
300284 # 重新绑定到内置连接池
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 ))
304287
305288 def get_conf (self ):
306289 """获取配置"""
0 commit comments