Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs regarding connector.start() & connector.stop() #34

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lcu_driver/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion lcu_driver/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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())