Debian Codegraph @

testing/web-platform/tests/tools/third_party/websockets/example/quickstart/show_time.py

raw
1 #!/usr/bin/env python
2
3 import asyncio
4 import datetime
5 import random
6 import websockets
7
8 async def show_time(websocket):
9 while True:
10 message = datetime.datetime.utcnow().isoformat() + "Z"
11 await websocket.send(message)
12 await asyncio.sleep(random.random() * 2 + 1)
13
14 async def main():
15 async with websockets.serve(show_time, "localhost", 5678):
16 await asyncio.Future() # run forever
17
18 if __name__ == "__main__":
19 asyncio.run(main())