Debian Codegraph @

testing/web-platform/tests/tools/third_party/websockets/example/faq/shutdown_client.py

raw
1 #!/usr/bin/env python
2
3 import asyncio
4 import signal
5 import websockets
6
7 async def client():
8 uri = "ws://localhost:8765"
9 async with websockets.connect(uri) as websocket:
10 # Close the connection when receiving SIGTERM.
11 loop = asyncio.get_running_loop()
12 loop.add_signal_handler(
13 signal.SIGTERM, loop.create_task, websocket.close())
14
15 # Process messages received on the connection.
16 async for message in websocket:
17 ...
18
19 asyncio.run(client())