class_docstr: Default CommManager singleton implementation for Comms in the Kernel
class_docstr_tok: ["Default","CommManager","singleton","implementation","for","Comms","in","the","Kernel"]
docstr: Handler for comm_open messages
docstr_tok: ["Handler","for","comm_open","messages"]
code: def comm_open(
      self, stream: ZMQStream, ident: str, msg: MessageType
  ) -> None:  # noqa: ARG002
      """Handler for comm_open messages"""
      from comm import create_comm
  
      content = msg["content"]
      comm_id = content["comm_id"]
      target_name = content["target_name"]
      f = self.targets.get(target_name, None)
      comm = create_comm(
          comm_id=comm_id,
          primary=False,
          target_name=target_name,
      )
      self.register_comm(comm)
      if f is None:
          logger.error(
              "No such comm target registered: %s", target_name
          )
      else:
          try:
              f(comm, msg)
              return
          except Exception:
              logger.error(
                  "Exception opening comm with target: %s",
                  target_name,
                  exc_info=True,
              )
  
      # Failure.
      try:
          comm.close()
      except Exception:
          logger.error(
              """Could not close comm during `comm_open` failure
                  clean-up.  The comm may not have been opened yet.""",
              exc_info=True,
          )
  
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 7 for calling the CommManager obj's underlying member method code with example usage: obj.comm_open(stream, ident, msg) without return types