From 8a18e4c743207b2f9dfc300a210a31c88656ce49 Mon Sep 17 00:00:00 2001 From: Will McGinnis Date: Thu, 3 Mar 2016 19:31:31 -0500 Subject: [PATCH] added close methods to everything below transport --- elasticsearch/connection/http_requests.py | 7 +++++++ elasticsearch/connection/http_urllib3.py | 6 ++++++ elasticsearch/connection/pooling.py | 7 +++++++ elasticsearch/connection_pool.py | 15 +++++++++++++++ elasticsearch/transport.py | 6 ++++++ 5 files changed, 41 insertions(+) diff --git a/elasticsearch/connection/http_requests.py b/elasticsearch/connection/http_requests.py index b97a94cf..e7c4c215 100644 --- a/elasticsearch/connection/http_requests.py +++ b/elasticsearch/connection/http_requests.py @@ -86,3 +86,10 @@ class RequestsHttpConnection(Connection): self.log_request_success(method, url, response.request.path_url, body, response.status_code, raw_data, duration) return response.status_code, response.headers, raw_data + + def close(self): + """ + Explicitly closes connections + """ + self.session.close() + return True \ No newline at end of file diff --git a/elasticsearch/connection/http_urllib3.py b/elasticsearch/connection/http_urllib3.py index d0f213f9..963ef043 100644 --- a/elasticsearch/connection/http_urllib3.py +++ b/elasticsearch/connection/http_urllib3.py @@ -113,3 +113,9 @@ class Urllib3HttpConnection(Connection): return response.status, response.getheaders(), raw_data + def close(self): + """ + Explicitly closes connection + """ + self.pool.close() + return True diff --git a/elasticsearch/connection/pooling.py b/elasticsearch/connection/pooling.py index a7721207..de653c03 100644 --- a/elasticsearch/connection/pooling.py +++ b/elasticsearch/connection/pooling.py @@ -24,3 +24,10 @@ class PoolingConnection(Connection): def _release_connection(self, con): self._free_connections.put(con) + + def close(self): + """ + Explicitly close connection + """ + return True + diff --git a/elasticsearch/connection_pool.py b/elasticsearch/connection_pool.py index c1e90cc9..eef5e6ad 100644 --- a/elasticsearch/connection_pool.py +++ b/elasticsearch/connection_pool.py @@ -227,6 +227,14 @@ class ConnectionPool(object): # only one connection, no need for a selector return connections[0] + def close(self): + """ + Explicitly closes connections + """ + for conn in self.connections: + conn.close() + + return True class DummyConnectionPool(ConnectionPool): def __init__(self, connections, **kwargs): @@ -241,6 +249,13 @@ class DummyConnectionPool(ConnectionPool): def get_connection(self): return self.connection + def close(self): + """ + Explicitly closes connections + """ + for conn in self.connections: + conn.close() + def _noop(self, *args, **kwargs): pass mark_dead = mark_live = resurrect = _noop diff --git a/elasticsearch/transport.py b/elasticsearch/transport.py index 505768d8..4e07972f 100644 --- a/elasticsearch/transport.py +++ b/elasticsearch/transport.py @@ -353,3 +353,9 @@ class Transport(object): data = self.deserializer.loads(data, headers.get('content-type')) return status, data + def close(self): + """ + Explcitly closes connections + """ + self.connection_pool.close() + return True