🌐 AI搜索 & 代理 主页
Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.

Commit 598813c

Browse files
committed
aio.Consul.close() uses aiohttp.ClientSession.close() which returns a coroutine that was never awaited. When this happens, RuntimeWarnings are raised on termination:
RuntimeWarning: coroutine 'ClientSession.close' was never awaited self._session.close() RuntimeWarning: Enable tracemalloc to get the object allocation traceback Unclosed client session client_session: <aiohttp.client.ClientSession object at 0x7fee7d894340> Unclosed connector connections: [<a long list of connections>] connector: <aiohttp.connector.TCPConnector object at 0x7fee7d894310> In this change the coroutine will be returned so it could be awaited and by that avoids these warnings.
1 parent 53eb41c commit 598813c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

consul/aio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __del__(self):
3636
if not self._session.closed:
3737
warnings.warn("Unclosed connector in aio.Consul.HTTPClient",
3838
ResourceWarning)
39-
self.close()
39+
self._loop.run_until_complete(self.close())
4040

4141
def get(self, callback, path, params=None):
4242
uri = self.uri(path, params)
@@ -55,7 +55,7 @@ def post(self, callback, path, params=None, data=''):
5555
return self._request(callback, 'POST', uri, data=data)
5656

5757
def close(self):
58-
self._session.close()
58+
return self._session.close()
5959

6060

6161
class Consul(base.Consul):
@@ -70,4 +70,4 @@ def connect(self, host, port, scheme, verify=True, cert=None):
7070

7171
def close(self):
7272
"""Close all opened http connections"""
73-
self.http.close()
73+
return self.http.close()

0 commit comments

Comments
 (0)