Debian Codegraph @

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

raw
1 #!/usr/bin/env python
2
3 import asyncio
4 import signal
5 import os
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.serve(
22 echo,
23 host="",
24 port=int(os.environ["PORT"]),
25 ):
26 await stop
27
28
29 if __name__ == "__main__":
30 asyncio.run(main())