code: def disconnect(self):
          
  
          if not self.connected:
              return
          self.connected = False
  
          self.connection.disconnect()
  
          if self._heartbeat_loop:
              self._heartbeat_loop.kill()
          self._recv_loop.kill()
  
          self._reset_attributes()
  
          self.emit(self.EVENT_DISCONNECTED)
docs: Close connection