Skip to content

Commit c40cedd

Browse files
authored
Merge pull request #179 from olegy-ait/fix/multiprocessing
Handle multiprocessing.pool.ThreadPool init on OS without shared memory for processes
2 parents acbdad0 + 4bef192 commit c40cedd

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

codegen/templates/api_client.mustache

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{>partial_header}}
33
from __future__ import absolute_import
44

5+
import logging
56
import datetime
67
import json
78
import mimetypes
@@ -63,7 +64,10 @@ class ApiClient(object):
6364
configuration = Configuration()
6465
self.configuration = configuration
6566

66-
self.pool = ThreadPool()
67+
try:
68+
self.pool = ThreadPool()
69+
except OSError:
70+
logging.warning('Looks like your system does not support ThreadPool but it will try without it if you do not use async requests')
6771
self.rest_client = rest.RESTClientObject(configuration)
6872
self.default_headers = {}
6973
if header_name is not None:
@@ -83,8 +87,9 @@ class ApiClient(object):
8387
)
8488

8589
def __del__(self):
86-
self.pool.close()
87-
self.pool.join()
90+
if hasattr(self, "pool"):
91+
self.pool.close()
92+
self.pool.join()
8893

8994
@property
9095
def user_agent(self):

0 commit comments

Comments
 (0)