MCPcopy Index your code
hub / github.com/python-websockets/websockets / watch

Function watch

example/tutorial/step3/app.py:143–163  ·  view source on GitHub ↗

Handle a connection from a spectator: watch an existing game.

(websocket, watch_key)

Source from the content-addressed store, hash-verified

141
142
143async def watch(websocket, watch_key):
144 """
145 Handle a connection from a spectator: watch an existing game.
146
147 """
148 # Find the Connect Four game.
149 try:
150 game, connected = WATCH[watch_key]
151 except KeyError:
152 await error(websocket, "Game not found.")
153 return
154
155 # Register to receive moves from this game.
156 connected.add(websocket)
157 try:
158 # Send previous moves, in case the game already started.
159 await replay(websocket, game)
160 # Keep the connection open, but don't receive any messages.
161 await websocket.wait_closed()
162 finally:
163 connected.remove(websocket)
164
165
166async def handler(websocket):

Callers 1

handlerFunction · 0.70

Calls 3

errorFunction · 0.70
replayFunction · 0.70
wait_closedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…