From 32749eabcd589bfe6d5d2af58a909f96d9bcae78 Mon Sep 17 00:00:00 2001 From: Vilnis Termanis Date: Fri, 16 Aug 2019 11:18:36 +0100 Subject: [PATCH] Expose close() method in client instances - Enable pooled/keep-alive connections to be closed explicitly --- botocore/client.py | 4 ++++ botocore/endpoint.py | 3 +++ botocore/httpsession.py | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/botocore/client.py b/botocore/client.py index f7b3a99de1..002a883990 100644 --- a/botocore/client.py +++ b/botocore/client.py @@ -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() diff --git a/botocore/endpoint.py b/botocore/endpoint.py index 2dbb119b59..f78d336cc8 100644 --- a/botocore/endpoint.py +++ b/botocore/endpoint.py @@ -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) diff --git a/botocore/httpsession.py b/botocore/httpsession.py index 447302b830..b4c3fa1f2a 100644 --- a/botocore/httpsession.py +++ b/botocore/httpsession.py @@ -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)