MCPcopy Index your code
hub / github.com/pyscript/pyscript / close

Method close

core/src/stdlib/pyscript/websocket.py:274–295  ·  view source on GitHub ↗

Close the WebSocket connection. Optionally specify a `code` (`int`) and a `reason` (`str`) for closing the connection. ```python # Normal close. ws.close() # Close with code and reason. ws.close(code=1000, reason="Task completed") ``

(self, code=None, reason=None)

Source from the content-addressed store, hash-verified

272 self._js_websocket.send(buffer)
273
274 def close(self, code=None, reason=None):
275 """
276 Close the WebSocket connection. Optionally specify a `code` (`int`)
277 and a `reason` (`str`) for closing the connection.
278
279 ```python
280 # Normal close.
281 ws.close()
282
283 # Close with code and reason.
284 ws.close(code=1000, reason="Task completed")
285 ```
286
287 Usage and values for `code` and `reasons`
288 [are explained here](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close).
289 """
290 if code and reason:
291 self._js_websocket.close(code, reason)
292 elif code:
293 self._js_websocket.close(code)
294 else:
295 self._js_websocket.close()

Callers 3

on_messageFunction · 0.80
second_handlerFunction · 0.80

Calls

no outgoing calls

Tested by 2

on_messageFunction · 0.64
second_handlerFunction · 0.64