docstr: Open the client connection
  
  Arg:
      state: the initial state description
docstr_tok: ["Open","the","client","connection","Arg",":","state",":","the","initial","state","description"]
code: def open(self, state: fos.StateDescription) -> None:
      """Open the client connection
  
      Arg:
          state: the initial state description
      """
      if not self._closed.is_set():
          raise RuntimeError("Client is already running")
  
      def run_client() -> None:
          def subscribe() -> None:
              response = requests.post(
                  f"{self.origin}/events",
                  stream=True,
                  headers={
                      "Accept": "text/event-stream",
                      "Content-type": "application/json",
                  },
                  data=json_util.dumps(
                      asdict(
                          ListenPayload(
                              events=[
                                  "capture_notebook_cell",
                                  "close_session",
                                  "reactivate_notebook_cell",
                                  "refresh",
                                  "reload_session",
                                  "select_labels",
                                  "select_samples",
                                  "set_color_scheme",
                                  "set_dataset_color_scheme",
                                  "set_group_slice",
                                  "set_spaces",
                                  "state_update",
                              ],
                              initializer=state,
                              subscription=self._subscription,
                          ),
                          dict_factory=dict_factory,
                      )
                  ),
              )
              source = sseclient.SSEClient(response)
              for message in source.events():
                  event = Event.from_data(message.event, message.data)
                  self._dispatch_event(event)
  
          while True:
              try:
                  _ping(f"{self.origin}/fiftyone")
                  self._connected = True
                  subscribe()
              except Exception as e:
                  if logger.level == logging.DEBUG or foc.DEV_INSTALL:
                      raise e
  
              if self._closed.is_set():
                  break
  
              self._connected = False
              print(
                  "\r\nCould not connect session, trying again "
                  "in 10 seconds\r\n"
              )
              time.sleep(10)
  
      self._thread = Thread(target=run_client, daemon=True)
      self._closed.clear()
      self._thread.start()
  
imports: from collections import defaultdict
  from dataclasses import asdict, dataclass
  import logging
  from retrying import retry
  from threading import Thread, Event
  import time
  import typing
  from bson import json_util
  import requests
  import sseclient
  from uuid import uuid4
  import fiftyone.constants
  import fiftyone.core.state
  from fiftyone.core.session.events import Event, EventType, ListenPayload, dict_factory
label_desc: Use image node_id 4 for calling the Client obj's underlying member method code with example usage: obj.open(state) without return types