feat: avoid creating unused ThreadPools (#91)
* feat: avoid creating unused ThreadPools * docs: add requested TODOs
This commit is contained in:
committed by
Kubernetes Prow Robot
parent
9cf654298a
commit
9d14077ba1
42
openapi/python-api_client.py.patch
Normal file
42
openapi/python-api_client.py.patch
Normal file
@@ -0,0 +1,42 @@
|
||||
--- a/kubernetes/client/api_client.py
|
||||
+++ b/kubernetes/client/api_client.py
|
||||
@@ -58,13 +58,15 @@ class ApiClient(object):
|
||||
'datetime': datetime,
|
||||
'object': object,
|
||||
}
|
||||
+ _pool = None
|
||||
|
||||
- def __init__(self, configuration=None, header_name=None, header_value=None, cookie=None):
|
||||
+ def __init__(self, configuration=None, header_name=None, header_value=None,
|
||||
+ cookie=None, pool_threads=None):
|
||||
if configuration is None:
|
||||
configuration = Configuration()
|
||||
self.configuration = configuration
|
||||
+ self.pool_threads = pool_threads
|
||||
|
||||
- self.pool = ThreadPool()
|
||||
self.rest_client = RESTClientObject(configuration)
|
||||
self.default_headers = {}
|
||||
if header_name is not None:
|
||||
@@ -74,8 +76,19 @@ class ApiClient(object):
|
||||
self.user_agent = 'Swagger-Codegen/8.0.0-snapshot/python'
|
||||
|
||||
def __del__(self):
|
||||
- self.pool.close()
|
||||
- self.pool.join()
|
||||
+ if self._pool:
|
||||
+ self._pool.close()
|
||||
+ self._pool.join()
|
||||
+ self._pool = None
|
||||
+
|
||||
+ @property
|
||||
+ def pool(self):
|
||||
+ """Create thread pool on first request
|
||||
+ avoids instantiating unused threadpool for blocking clients.
|
||||
+ """
|
||||
+ if self._pool is None:
|
||||
+ self._pool = ThreadPool(self.pool_threads)
|
||||
+ return self._pool
|
||||
|
||||
@property
|
||||
def user_agent(self):
|
||||
Reference in New Issue
Block a user