Thanks to visit codestin.com
Credit goes to github.com

Skip to content

added async_req parameter (default to True) to ApiClient constructor #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions kubernetes/client/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ class ApiClient(object):
'object': object,
}

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, async_req=True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is auto-generated by swagger-codegen. You could contribute to swagger-codegen python template. When you did, we can import the changes here. Ref: #226

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roycaihw sure, can migrate the code change there, but other than that, the code looks ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code change makes sense to me, although I'm not a python expert :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@huang195 looks good to me. please do follow the path mentioned by @roycaihw

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created the PR here: swagger-api/swagger-codegen#7782

if configuration is None:
configuration = Configuration()
self.configuration = configuration

self.pool = ThreadPool()
self.async_req = async_req
if async_req:
self.pool = ThreadPool()
self.rest_client = RESTClientObject(configuration)
self.default_headers = {}
if header_name is not None:
Expand All @@ -74,8 +76,9 @@ def __init__(self, configuration=None, header_name=None, header_value=None, cook
self.user_agent = 'Swagger-Codegen/5.0.0-snapshot/python'

def __del__(self):
self.pool.close()
self.pool.join()
if self.async_req:
self.pool.close()
self.pool.join()

@property
def user_agent(self):
Expand Down Expand Up @@ -313,7 +316,7 @@ def call_api(self, resource_path, method,
If parameter async is False or missing,
then the method will return the response directly.
"""
if not async:
if not async or not self.async_req:
return self.__call_api(resource_path, method,
path_params, query_params, header_params,
body, post_params, files,
Expand Down
10 changes: 10 additions & 0 deletions kubernetes/e2e_test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,13 @@ def test_node_apis(self):
node = api.read_node(name=item.metadata.name)
self.assertTrue(len(node.metadata.labels) > 0)
self.assertTrue(isinstance(node.metadata.labels, dict))

def test_sync_node_apis(self):
client = api_client.ApiClient(configuration=self.config, async_req=False)
api = core_v1_api.CoreV1Api(client)

for item in api.list_node().items:
node = api.read_node(name=item.metadata.name)
self.assertTrue(len(node.metadata.labels) > 0)
self.assertTrue(isinstance(node.metadata.labels, dict))