Close the connection. **Always call this method when you are done sending events.**
(self, code: int = None, reason: str = None)
| 985 | return bytes(payload) |
| 986 | |
| 987 | def close(self, code: int = None, reason: str = None): |
| 988 | """ |
| 989 | Close the connection. |
| 990 | |
| 991 | **Always call this method when you are done sending events.** |
| 992 | """ |
| 993 | if self.closed: |
| 994 | return |
| 995 | |
| 996 | self._reset_fragmented_message() |
| 997 | |
| 998 | payload = self._prepare_close_payload(code, reason) |
| 999 | try: |
| 1000 | self.send_message(payload, Websocket.CLOSE, fail_silently=True) |
| 1001 | except (BrokenPipeError, OSError): |
| 1002 | pass |
| 1003 | self._close_connection() |
| 1004 | self.closed = True |
no test coverage detected