Skip to content

Commit

Permalink
fix websocket_server.py to work with python 3.12
Browse files Browse the repository at this point in the history
  • Loading branch information
arvidn committed Nov 16, 2024
1 parent dea2b30 commit 9a83485
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions test/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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:
Expand All @@ -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()

0 comments on commit 9a83485

Please sign in to comment.