Close the server. * Close the underlying :class:`asyncio.Server`. * When ``close_connections`` is :obj:`True`, which is the default, close existing connections. Specifically: * Reject opening WebSocket connections with an HTTP 503 (service u
(
self,
close_connections: bool = True,
code: CloseCode | int = CloseCode.GOING_AWAY,
reason: str = "",
)
| 406 | self.handlers[connection] = self.loop.create_task(self.conn_handler(connection)) |
| 407 | |
| 408 | def close( |
| 409 | self, |
| 410 | close_connections: bool = True, |
| 411 | code: CloseCode | int = CloseCode.GOING_AWAY, |
| 412 | reason: str = "", |
| 413 | ) -> None: |
| 414 | """ |
| 415 | Close the server. |
| 416 | |
| 417 | * Close the underlying :class:`asyncio.Server`. |
| 418 | * When ``close_connections`` is :obj:`True`, which is the default, close |
| 419 | existing connections. Specifically: |
| 420 | |
| 421 | * Reject opening WebSocket connections with an HTTP 503 (service |
| 422 | unavailable) error. This happens when the server accepted the TCP |
| 423 | connection but didn't complete the opening handshake before closing. |
| 424 | * Close open WebSocket connections with code 1001 (going away). |
| 425 | ``code`` and ``reason`` can be customized, for example to use code |
| 426 | 1012 (service restart). |
| 427 | |
| 428 | * Wait until all connection handlers terminate. |
| 429 | |
| 430 | :meth:`close` is idempotent. |
| 431 | |
| 432 | """ |
| 433 | if self.close_task is None: |
| 434 | self.close_task = self.get_loop().create_task( |
| 435 | self._close(close_connections, code, reason) |
| 436 | ) |
| 437 | |
| 438 | async def _close( |
| 439 | self, |
no test coverage detected