Improve aiohttp default clientsession close with connector (#5208)

This commit is contained in:
Pascal Vizeli 2017-01-07 21:11:19 +01:00 committed by GitHub
parent 81922b88a2
commit ca4a857532
2 changed files with 5 additions and 3 deletions

View File

@ -34,7 +34,6 @@ def async_get_clientsession(hass, verify_ssl=True):
connector=connector,
headers={USER_AGENT: SERVER_SOFTWARE}
)
_async_register_clientsession_shutdown(hass, clientsession)
hass.data[key] = clientsession
return hass.data[key]
@ -111,8 +110,12 @@ def async_cleanup_websession(hass):
This method is a coroutine.
"""
tasks = []
if DATA_CLIENTSESSION in hass.data:
hass.data[DATA_CLIENTSESSION].detach()
if DATA_CONNECTOR in hass.data:
tasks.append(hass.data[DATA_CONNECTOR].close())
if DATA_CLIENTSESSION_NOTVERIFY in hass.data:
hass.data[DATA_CLIENTSESSION_NOTVERIFY].detach()
if DATA_CONNECTOR_NOTVERIFY in hass.data:
tasks.append(hass.data[DATA_CONNECTOR_NOTVERIFY].close())

View File

@ -284,8 +284,7 @@ class TestMediaPlayerWeb(unittest.TestCase):
def get(self, url):
return MockResponse()
@asyncio.coroutine
def close(self):
def detach(self):
pass
self.hass.data[DATA_CLIENTSESSION] = MockWebsession()