Skip to content

Commit

Permalink
Expose close() method in client instances
Browse files Browse the repository at this point in the history
- Enable pooled/keep-alive connections to be closed explicitly
  • Loading branch information
vtermanis committed Aug 16, 2019
1 parent b51e1f6 commit 32749ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions botocore/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,10 @@ def __getattr__(self, item):
self.__class__.__name__, item)
)

def close(self):
"""Closes underlying endpoint connections."""
self._endpoint.close()

def _register_handlers(self):
# Register the handler required to sign requests.
service_id = self.meta.service_model.service_id.hyphenize()
Expand Down
3 changes: 3 additions & 0 deletions botocore/endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ def __init__(self, host, endpoint_prefix, event_emitter,
def __repr__(self):
return '%s(%s)' % (self._endpoint_prefix, self.host)

def close(self):
self.http_session.close()

def make_request(self, operation_model, request_dict):
logger.debug("Making request for %s with params: %s",
operation_model, request_dict)
Expand Down
5 changes: 5 additions & 0 deletions botocore/httpsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ def _get_request_target(self, url, proxy_url):
def _chunked(self, headers):
return headers.get('Transfer-Encoding', '') == 'chunked'

def close(self):
self._manager.clear()
for manager in self._proxy_managers.values():
manager.clear()

def send(self, request):
try:
proxy_url = self._proxy_config.proxy_url_for(request.url)
Expand Down

0 comments on commit 32749ea

Please sign in to comment.