MCPcopy Create free account
hub / github.com/EasyIME/PIME / close

Method close

python/python3/tornado/websocket.py:1250–1280  ·  view source on GitHub ↗

Closes the WebSocket connection.

(self, code: Optional[int] = None, reason: Optional[str] = None)

Source from the content-addressed store, hash-verified

1248 return None
1249
1250 def close(self, code: Optional[int] = None, reason: Optional[str] = None) -> None:
1251 """Closes the WebSocket connection."""
1252 if not self.server_terminated:
1253 if not self.stream.closed():
1254 if code is None and reason is not None:
1255 code = 1000 # "normal closure" status code
1256 if code is None:
1257 close_data = b""
1258 else:
1259 close_data = struct.pack(">H", code)
1260 if reason is not None:
1261 close_data += utf8(reason)
1262 try:
1263 self._write_frame(True, 0x8, close_data)
1264 except StreamClosedError:
1265 self._abort()
1266 self.server_terminated = True
1267 if self.client_terminated:
1268 if self._waiting is not None:
1269 self.stream.io_loop.remove_timeout(self._waiting)
1270 self._waiting = None
1271 self.stream.close()
1272 elif self._waiting is None:
1273 # Give the client a few seconds to complete a clean shutdown,
1274 # otherwise just close the connection.
1275 self._waiting = self.stream.io_loop.add_timeout(
1276 self.stream.io_loop.time() + 5, self._abort
1277 )
1278 if self.ping_callback:
1279 self.ping_callback.stop()
1280 self.ping_callback = None
1281
1282 def is_closing(self) -> bool:
1283 """Return ``True`` if this connection is closing.

Callers 3

_receive_frameMethod · 0.95
_handle_messageMethod · 0.95
periodic_pingMethod · 0.95

Calls 9

_write_frameMethod · 0.95
utf8Function · 0.90
closedMethod · 0.80
_abortMethod · 0.80
add_timeoutMethod · 0.80
timeMethod · 0.80
remove_timeoutMethod · 0.45
closeMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected