From 0440659ec64c923a0c26188666f3c68121501400 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Thu, 21 May 2020 21:29:33 +0200 Subject: Properly handle disconnections from remote end Signed-off-by: Olivier Gayot --- swiftstory/SwiftStory.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/swiftstory/SwiftStory.py b/swiftstory/SwiftStory.py index de3eab8..256c2be 100644 --- a/swiftstory/SwiftStory.py +++ b/swiftstory/SwiftStory.py @@ -2,6 +2,7 @@ import argparse import asyncio +import contextlib import json import websockets @@ -62,8 +63,9 @@ async def message_received_handler(client, websocket, message): async def swiftstory(websocket, path): client = Client(websocket, game_manager) - async for message in websocket: - await message_received_handler(client, websocket, message) + with contextlib.suppress(websockets.exceptions.ConnectionClosed): + async for message in websocket: + await message_received_handler(client, websocket, message) await client.disconnect() -- cgit v1.2.3