code: def close(self, code=1000, message=''):
          
          try:
              message = self._encode_bytes(message)
              self.send_frame(
                  struct.pack('!H%ds' % len(message), code, message),
                  opcode=self.OPCODE_CLOSE)
          except WebSocketError:
              # Failed to write the closing frame but it's ok because we're
              # closing the socket anyway.
              logger.debug("Failed to write closing frame -> closing socket")
          finally:
              logger.debug("Closed WebSocket")
              self._closed = True
              self.stream = None
docs: Close the websocket and connection, sending the specified code and
          message.  The underlying socket object is _not_ closed, that is the
          responsibility of the initiator.