code: def _subscribe_new(tensor, side_effects, control_cache):
      """Helper method that subscribes a single tensor to a list of side_effects.
  
      Args:
        tensor: `tf.Tensor`
        side_effects: List of side_effect functions see subscribe for details.
        control_cache: `_ControlOutputCache` helper to get control_outputs faster.
  
      Returns:
        The modified replacement to the passed in tensor which triggers the side
        effects.
      """
      update_input = []
      for consumer_op in list(tensor.consumers()):  # explicit copy
          update_input.append(
              (consumer_op, list(consumer_op.inputs).index(tensor))
          )
  
      update_control_input = control_cache.get_control_outputs(
          tensor.op
      )
  
      # Trailing slash on name scope to replace the scope.
      name_scope = tensor.op.name + "/subscription/"
      with ops.name_scope(name_scope):
          outs = []
          for s in side_effects:
              outs += s(tensor)
  
          with ops.control_dependencies(outs):
              out = array_ops.identity(tensor)
  
      for consumer_op, index in update_input:
          consumer_op._update_input(
              index, out
          )  # pylint: disable=protected-access
  
      for consumer_op in update_control_input:
          # If an op has more than one output and two or more of its output tensors
          # are subscribed at the same time, we remove the control dependency from
          # the original op only once and we add the dependencies to all the
          # new identities.
          new_control_inputs = consumer_op.control_inputs
          if tensor.op in new_control_inputs:
              new_control_inputs.remove(tensor.op)
          new_control_inputs.append(out.op)
          # pylint: disable=protected-access
          consumer_op._remove_all_control_inputs()
          consumer_op._add_control_inputs(new_control_inputs)
          # pylint: enable=protected-access
      return out
  
file_path: tensorflow-upstream/tensorflow/python/framework/subscribe.py
imports: import contextlib
  import re
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import tf_logging
label_desc: Use image node_id 2 for calling a global function with example usage: _subscribe_new(tensor, side_effects, control_cache) and returns: out