From 9a83485a20349b03f958de70e28d7f583a92938a Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sat, 16 Nov 2024 11:09:43 +0100 Subject: [PATCH] fix websocket_server.py to work with python 3.12 --- test/websocket_server.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/websocket_server.py b/test/websocket_server.py index 7b461b00bd2..9cc2078bbe6 100755 --- a/test/websocket_server.py +++ b/test/websocket_server.py @@ -17,7 +17,7 @@ logger.addHandler(logging.StreamHandler(sys.stdout)) -async def handle(websocket, path): +async def handle(websocket): try: while True: message = await websocket.recv() @@ -40,10 +40,9 @@ async def handle(websocket, path): print(e) -if __name__ == '__main__': +async def main() -> None: port = int(sys.argv[1]) use_ssl = sys.argv[2] != '0' - min_interval = sys.argv[3] print('python version: %s' % sys.version_info.__str__()) if use_ssl: @@ -52,6 +51,9 @@ async def handle(websocket, path): else: ssl_context = None - start_server = websockets.serve(handle, '127.0.0.1', port, ssl=ssl_context) - asyncio.get_event_loop().run_until_complete(start_server) + await websockets.serve(handle, '127.0.0.1', port, ssl=ssl_context) + +if __name__ == '__main__': + loop = asyncio.get_event_loop() + asyncio.get_event_loop().run_until_complete(main()) asyncio.get_event_loop().run_forever()