diff --git a/src/main/resources/handlebars/python/api_client.mustache b/src/main/resources/handlebars/python/api_client.mustache index 5c62fff24f..57379693a9 100644 --- a/src/main/resources/handlebars/python/api_client.mustache +++ b/src/main/resources/handlebars/python/api_client.mustache @@ -60,7 +60,7 @@ class ApiClient(object): configuration = Configuration() self.configuration = configuration - self.pool = ThreadPool() + self._pool = None # Use the pool property to lazily initialize the ThreadPool. self.rest_client = rest.RESTClientObject(configuration) self.default_headers = {} if header_name is not None: @@ -70,8 +70,15 @@ class ApiClient(object): self.user_agent = '{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{{packageVersion}}}/python{{/httpUserAgent}}' def __del__(self): - self.pool.close() - self.pool.join() + if self._pool is not None: + self._pool.close() + self._pool.join() + + @property + def pool(self): + if self._pool is None: + self._pool = ThreadPool() + return self._pool @property def user_agent(self):