Debian Codegraph @

testing/web-platform/tests/tools/third_party/websockets/example/deployment/fly/app.py

raw
1 #!/usr/bin/env python
2
3 import asyncio
4 import http
5 import signal
6
7 import websockets
8
9
10 async def echo(websocket):
11 async for message in websocket:
12 await websocket.send(message)
13
14
15 async def health_check(path, request_headers):
16 if path == "/healthz":
17 return http.HTTPStatus.OK, [], b"OK\n"
18
19
20 async def main():
21 # Set the stop condition when receiving SIGTERM.
22 loop = asyncio.get_running_loop()
23 stop = loop.create_future()
24 loop.add_signal_handler(signal.SIGTERM, stop.set_result, None)
25
26 async with websockets.serve(
27 echo,
28 host="",
29 port=8080,
30 process_request=health_check,
31 ):
32 await stop
33
34
35 if __name__ == "__main__":
36 asyncio.run(main())