Debian Codegraph @

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

raw
1 #!/usr/bin/env python
2
3 import asyncio
4 import os
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 main():
16 # Set the stop condition when receiving SIGTERM.
17 loop = asyncio.get_running_loop()
18 stop = loop.create_future()
19 loop.add_signal_handler(signal.SIGTERM, stop.set_result, None)
20
21 async with websockets.unix_serve(
22 echo,
23 path=f"{os.environ['SUPERVISOR_PROCESS_NAME']}.sock",
24 ):
25 await stop
26
27
28 if __name__ == "__main__":
29 asyncio.run(main())