forked from loafle/openapi-generator-original
[python/asyncio] explicitly close client session via async context manager (#5621)
This commit is contained in:
@@ -81,13 +81,14 @@ class ApiClient(object):
|
||||
self.user_agent = 'OpenAPI-Generator/1.0.0/python'
|
||||
self.client_side_validation = configuration.client_side_validation
|
||||
|
||||
def __enter__(self):
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.close()
|
||||
async def __aexit__(self, exc_type, exc_value, traceback):
|
||||
await self.close()
|
||||
|
||||
def close(self):
|
||||
async def close(self):
|
||||
await self.rest_client.close()
|
||||
if self._pool:
|
||||
self._pool.close()
|
||||
self._pool.join()
|
||||
|
||||
@@ -18,7 +18,6 @@ import ssl
|
||||
|
||||
import aiohttp
|
||||
import certifi
|
||||
import asyncio
|
||||
# python 2 and python 3 compatibility library
|
||||
from six.moves.urllib.parse import urlencode
|
||||
|
||||
@@ -85,8 +84,8 @@ class RESTClientObject(object):
|
||||
connector=connector
|
||||
)
|
||||
|
||||
def __del__(self):
|
||||
asyncio.ensure_future(self.pool_manager.close())
|
||||
async def close(self):
|
||||
await self.pool_manager.close()
|
||||
|
||||
async def request(self, method, url, query_params=None, headers=None,
|
||||
body=None, post_params=None, _preload_content=True,
|
||||
|
||||
Reference in New Issue
Block a user