-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathpython-api_client.py.patch
42 lines (38 loc) · 1.38 KB
/
python-api_client.py.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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):