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

Function watch

example/tutorial/step2/app.py:140–160  ·  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

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