diff options
Diffstat (limited to 'testing/web-platform/tests/tools/third_party/websockets/example/faq/shutdown_client.py')
-rw-r--r-- | testing/web-platform/tests/tools/third_party/websockets/example/faq/shutdown_client.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/testing/web-platform/tests/tools/third_party/websockets/example/faq/shutdown_client.py b/testing/web-platform/tests/tools/third_party/websockets/example/faq/shutdown_client.py new file mode 100644 index 0000000000..539dd0304a --- /dev/null +++ b/testing/web-platform/tests/tools/third_party/websockets/example/faq/shutdown_client.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python + +import asyncio +import signal +import websockets + +async def client(): + uri = "ws://localhost:8765" + async with websockets.connect(uri) as websocket: + # Close the connection when receiving SIGTERM. + loop = asyncio.get_running_loop() + loop.add_signal_handler( + signal.SIGTERM, loop.create_task, websocket.close()) + + # Process messages received on the connection. + async for message in websocket: + ... + +asyncio.run(client()) |