diff options
author | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-05-21 21:29:33 +0200 |
---|---|---|
committer | Olivier Gayot <olivier.gayot@sigexec.com> | 2020-05-21 21:29:33 +0200 |
commit | 0440659ec64c923a0c26188666f3c68121501400 (patch) | |
tree | 00a784e83d05aef4a038d41273a20004c894b6a0 /swiftstory/SwiftStory.py | |
parent | a1a39058e0f5b71d029eaf26c6950ae8e7a23ad6 (diff) |
Properly handle disconnections from remote end
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
Diffstat (limited to 'swiftstory/SwiftStory.py')
-rw-r--r-- | swiftstory/SwiftStory.py | 6 |
1 files 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() |