From 8dd8f6c17ef28fe4affc635c8ddead8a5e3681d0 Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Sun, 8 Dec 2024 10:37:55 +1000 Subject: [PATCH 1/2] add robustness to multiprocessing failure, this might happen for processes running in a suexec environment --- amazon_paapi/sdk/api_client.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/amazon_paapi/sdk/api_client.py b/amazon_paapi/sdk/api_client.py index e14223e..670c4b8 100644 --- a/amazon_paapi/sdk/api_client.py +++ b/amazon_paapi/sdk/api_client.py @@ -88,9 +88,12 @@ def __init__(self, configuration = Configuration() self.configuration = configuration - self.pool = ThreadPool() - self.rest_client = rest.RESTClientObject(configuration) - self.default_headers = {} + try: + self.pool = ThreadPool() + except: + # if multiprocessing is not available, we can't use the pool self.rest_client = rest.RESTClientObject(configuration) + self.default_headers = {} + if header_name is not None: self.default_headers[header_name] = header_value self.cookie = cookie @@ -103,8 +106,9 @@ def __init__(self, self.region = region def __del__(self): - self.pool.close() - self.pool.join() + if self.pool is not None: + self.pool.close() + self.pool.join() @property def user_agent(self): From c7edb1bb88f64a29d485f5f628a57b67ab0816d1 Mon Sep 17 00:00:00 2001 From: Peter Corke Date: Sun, 8 Dec 2024 11:00:13 +1000 Subject: [PATCH 2/2] fix cut and paste error --- amazon_paapi/sdk/api_client.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/amazon_paapi/sdk/api_client.py b/amazon_paapi/sdk/api_client.py index 670c4b8..73bd001 100644 --- a/amazon_paapi/sdk/api_client.py +++ b/amazon_paapi/sdk/api_client.py @@ -91,9 +91,11 @@ def __init__(self, try: self.pool = ThreadPool() except: - # if multiprocessing is not available, we can't use the pool self.rest_client = rest.RESTClientObject(configuration) - self.default_headers = {} + # if multiprocessing is not available, we can't use the pool + self.pool = None + self.rest_client = rest.RESTClientObject(configuration) + self.default_headers = {} if header_name is not None: self.default_headers[header_name] = header_value self.cookie = cookie