From 4bef19277e28e40f04b79bfac8b54ccb3df6c281 Mon Sep 17 00:00:00 2001 From: Oleg Yrchenko Date: Thu, 17 Aug 2023 18:29:34 +0300 Subject: [PATCH] Handle multiprocessing.pool init AWS Lambda does not support multiprocessing.Queue or multiprocessing.Pool Therefore the lib cannot init ThreadPool. This commit adds a posibility do not init ThreadPool if the OS does not support ThreadPool. As far as async_req is disabled by default no need to change other functions. --- codegen/templates/api_client.mustache | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/codegen/templates/api_client.mustache b/codegen/templates/api_client.mustache index 0d65296f..a633f46c 100644 --- a/codegen/templates/api_client.mustache +++ b/codegen/templates/api_client.mustache @@ -2,6 +2,7 @@ {{>partial_header}} from __future__ import absolute_import +import logging import datetime import json import mimetypes @@ -63,7 +64,10 @@ class ApiClient(object): configuration = Configuration() self.configuration = configuration - self.pool = ThreadPool() + try: + self.pool = ThreadPool() + except OSError: + logging.warning('Looks like your system does not support ThreadPool but it will try without it if you do not use async requests') self.rest_client = rest.RESTClientObject(configuration) self.default_headers = {} if header_name is not None: @@ -83,8 +87,9 @@ class ApiClient(object): ) def __del__(self): - self.pool.close() - self.pool.join() + if hasattr(self, "pool"): + self.pool.close() + self.pool.join() @property def user_agent(self):