修复取消订阅房间崩溃的bug
This commit is contained in:
20
main.py
20
main.py
@@ -44,7 +44,7 @@ def on_room_changed(new_room_ids):
|
|||||||
TEST_ROOM_IDS = list(set(new_room_ids + room_from_config()))
|
TEST_ROOM_IDS = list(set(new_room_ids + room_from_config()))
|
||||||
|
|
||||||
for removed in clients.keys() - TEST_ROOM_IDS:
|
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]
|
del clients[removed]
|
||||||
|
|
||||||
if removed in log_files:
|
if removed in log_files:
|
||||||
@@ -52,12 +52,16 @@ def on_room_changed(new_room_ids):
|
|||||||
del log_files[removed]
|
del log_files[removed]
|
||||||
|
|
||||||
for added in TEST_ROOM_IDS - clients.keys():
|
for added in TEST_ROOM_IDS - clients.keys():
|
||||||
client = None
|
asyncio.create_task(connect_room_safety(added))
|
||||||
try:
|
|
||||||
client = asyncio.run(connect_room(added))
|
|
||||||
except Exception as e:
|
async def connect_room_safety(room_id: str):
|
||||||
if client is not None:
|
client = None
|
||||||
asyncio.run(client.stop_and_close())
|
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():
|
async def main():
|
||||||
@@ -166,7 +170,7 @@ room_status_log = open("logs/room_status.jsonl", "a", encoding="utf-8")
|
|||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
clients = {}
|
clients: dict[str, blivedm.BLiveClient] = {}
|
||||||
log_files = {}
|
log_files = {}
|
||||||
|
|
||||||
with open("cookie.txt", "r", encoding="utf-8") as f:
|
with open("cookie.txt", "r", encoding="utf-8") as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user