From dda30309a48370bb3d82c8723993490972613223 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Mon, 8 Apr 2019 17:03:19 +0300 Subject: refactoring --- kvmd/apps/kvmd/streamer.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py index bf1361f0..84eb68a2 100644 --- a/kvmd/apps/kvmd/streamer.py +++ b/kvmd/apps/kvmd/streamer.py @@ -117,11 +117,11 @@ class Streamer: # pylint: disable=too-many-instance-attributes return dict(self.__params) async def get_state(self) -> Dict: - self.__ensure_session() + session = self.__ensure_session() url = "http://%s:%d/state" % (self.__host, self.__port) state = None try: - async with self.__http_session.get(url, timeout=self.__timeout) as response: # type: ignore + async with session.get(url, timeout=self.__timeout) as response: response.raise_for_status() state = (await response.json())["result"] except (aiohttp.ClientConnectionError, aiohttp.ServerConnectionError): @@ -158,12 +158,13 @@ class Streamer: # pylint: disable=too-many-instance-attributes await self.__http_session.close() self.__http_session = None - def __ensure_session(self) -> None: + def __ensure_session(self) -> aiohttp.ClientSession: if not self.__http_session: if self.__unix_path: self.__http_session = aiohttp.ClientSession(connector=aiohttp.UnixConnector(path=self.__unix_path)) else: self.__http_session = aiohttp.ClientSession() + return self.__http_session async def __inner_start(self) -> None: assert not self.__streamer_task -- cgit v1.2.3