diff --git a/main.py b/main.py index b086224..8489b54 100644 --- a/main.py +++ b/main.py @@ -44,7 +44,7 @@ def on_room_changed(new_room_ids): TEST_ROOM_IDS = list(set(new_room_ids + room_from_config())) for removed in clients.keys() - TEST_ROOM_IDS: - asyncio.run(clients[removed].stop_and_close()) + asyncio.create_task(clients[removed].stop_and_close()) del clients[removed] if removed in log_files: @@ -52,12 +52,16 @@ def on_room_changed(new_room_ids): del log_files[removed] for added in TEST_ROOM_IDS - clients.keys(): - client = None - try: - client = asyncio.run(connect_room(added)) - except Exception as e: - if client is not None: - asyncio.run(client.stop_and_close()) + asyncio.create_task(connect_room_safety(added)) + + +async def connect_room_safety(room_id: str): + client = None + try: + client = await connect_room(room_id) + except Exception as e: + if client is not None: + asyncio.create_task(client.stop_and_close()) async def main(): @@ -166,7 +170,7 @@ room_status_log = open("logs/room_status.jsonl", "a", encoding="utf-8") logger = logging.getLogger() -clients = {} +clients: dict[str, blivedm.BLiveClient] = {} log_files = {} with open("cookie.txt", "r", encoding="utf-8") as f: