class_docstr: Class for communicating between a Frontend and a Kernel
  
  Must be subclassed with a publish_msg method implementation which
  sends comm messages through the iopub channel.
class_docstr_tok: ["Class","for","communicating","between","a","Frontend","and","a","Kernel","Must","be","subclassed","with","a","publish_msg","method","implementation","which","sends","comm","messages","through","the","iopub","channel","."]
code: def __init__(
      self,
      target_name: str = "comm",
      data: MaybeDict = None,
      metadata: MaybeDict = None,
      buffers: BuffersType = None,
      comm_id: str | None = None,
      primary: bool = True,
      target_module: str | None = None,
      topic: bytes | None = None,
      _open_data: MaybeDict = None,
      _close_data: MaybeDict = None,
      **kwargs: t.Any,
  ) -> None:
      super().__init__(**kwargs)
  
      self.comm_id = comm_id if comm_id else uuid.uuid4().hex
      self.primary = primary
      self.target_name = target_name
      self.target_module = target_module
      self.topic = (
          topic if topic else ("comm-%s" % self.comm_id).encode("ascii")
      )
  
      self._open_data = _open_data if _open_data else {}
      self._close_data = _close_data if _close_data else {}
  
      self._msg_callback: CommCallback | None = None
      self._close_callback: CommCallback | None = None
  
      self._closed = True
  
      if self.primary:
          # I am primary, open my peer.
          self.open(data=data, metadata=metadata, buffers=buffers)
      else:
          self._closed = False
  
imports: from __future__ import annotations
  import contextlib
  import logging
  import typing
  import uuid
  from traitlets.utils.importstring import import_item
  import comm
label_desc: Use image node_id 1 to create a new BaseComm object  with example: obj = BaseComm(target_name, data, metadata, buffers, comm_id, primary, target_module, topic, _open_data, _close_data)