diff --git a/lcu_driver/connection.py b/lcu_driver/connection.py index 77c82e0..3ec5b09 100644 --- a/lcu_driver/connection.py +++ b/lcu_driver/connection.py @@ -184,7 +184,7 @@ async def run_ws(self): data = loads(msg.data)[2] self._connector.ws.match_event(self._connector, self, data) except JSONDecodeError: - logger.warning('Error decoding the following JSON: ', msg.data) + logger.warning(f'Error decoding the following JSON: {msg.data}') elif msg.type == aiohttp.WSMsgType.CLOSED: break diff --git a/lcu_driver/connector.py b/lcu_driver/connector.py index 694b85d..86ab876 100644 --- a/lcu_driver/connector.py +++ b/lcu_driver/connector.py @@ -86,6 +86,7 @@ class MultipleClientConnector(BaseConnector): def __init__(self, *, loop=None): super().__init__(loop=loop) self.connections = [] + self.stop_event = asyncio.Event() # Event to signal stop def register_connection(self, connection): self.connections.append(connection) @@ -108,7 +109,7 @@ def _process_was_initialized(self, non_initialized_connection): async def _astart(self): tasks = [] try: - while True: + while not self.stop_event.is_set(): process_iter = _return_ux_process() process = next(process_iter, None) @@ -124,6 +125,12 @@ async def _astart(self): logger.info('Event loop interrupted by keyboard') finally: await asyncio.gather(*tasks) + await self.stop() + + async def stop(self): + self.stop_event.set() def start(self) -> None: + self.stop_event.clear() # Reset the stop event state self.loop.run_until_complete(self._astart()) +