Skip to content

Commit 8a18e4c

Browse files
author
Will McGinnis
committed
added close methods to everything below transport
1 parent 4de7835 commit 8a18e4c

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

elasticsearch/connection/http_requests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,10 @@ def perform_request(self, method, url, params=None, body=None, timeout=None, ign
8686
self.log_request_success(method, url, response.request.path_url, body, response.status_code, raw_data, duration)
8787

8888
return response.status_code, response.headers, raw_data
89+
90+
def close(self):
91+
"""
92+
Explicitly closes connections
93+
"""
94+
self.session.close()
95+
return True

elasticsearch/connection/http_urllib3.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,9 @@ def perform_request(self, method, url, params=None, body=None, timeout=None, ign
113113

114114
return response.status, response.getheaders(), raw_data
115115

116+
def close(self):
117+
"""
118+
Explicitly closes connection
119+
"""
120+
self.pool.close()
121+
return True

elasticsearch/connection/pooling.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ def _get_connection(self):
2424

2525
def _release_connection(self, con):
2626
self._free_connections.put(con)
27+
28+
def close(self):
29+
"""
30+
Explicitly close connection
31+
"""
32+
return True
33+

elasticsearch/connection_pool.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ def get_connection(self):
227227
# only one connection, no need for a selector
228228
return connections[0]
229229

230+
def close(self):
231+
"""
232+
Explicitly closes connections
233+
"""
234+
for conn in self.connections:
235+
conn.close()
236+
237+
return True
230238

231239
class DummyConnectionPool(ConnectionPool):
232240
def __init__(self, connections, **kwargs):
@@ -241,6 +249,13 @@ def __init__(self, connections, **kwargs):
241249
def get_connection(self):
242250
return self.connection
243251

252+
def close(self):
253+
"""
254+
Explicitly closes connections
255+
"""
256+
for conn in self.connections:
257+
conn.close()
258+
244259
def _noop(self, *args, **kwargs):
245260
pass
246261
mark_dead = mark_live = resurrect = _noop

elasticsearch/transport.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,9 @@ def perform_request(self, method, url, params=None, body=None):
353353
data = self.deserializer.loads(data, headers.get('content-type'))
354354
return status, data
355355

356+
def close(self):
357+
"""
358+
Explcitly closes connections
359+
"""
360+
self.connection_pool.close()
361+
return True

0 commit comments

Comments
 (0)