code: def default_session(session):
      """Python "with" handler for defining a default session.
  
      This function provides a means of registering a session for handling
      Tensor.eval() and Operation.run() calls. It is primarily intended for use
      by session.Session, but can be used with any object that implements
      the Session.run() interface.
  
      Use with the "with" keyword to specify that Tensor.eval() and Operation.run()
      invocations within the scope of a block should be executed by a particular
      session.
  
      The default session applies to the current thread only, so it is always
      possible to inspect the call stack and determine the scope of a default
      session. If you create a new thread, and wish to use the default session
      in that thread, you must explicitly add a "with ops.default_session(sess):"
      block in that thread's function.
  
      Example:
        The following code examples are equivalent:
  
        # 1. Using the Session object directly:
        sess = ...
        c = tf.constant(5.0)
        sess.run(c)
  
        # 2. Using default_session():
        sess = ...
        with ops.default_session(sess):
          c = tf.constant(5.0)
          result = c.eval()
  
        # 3. Overriding default_session():
        sess = ...
        with ops.default_session(sess):
          c = tf.constant(5.0)
          with ops.default_session(...):
            c.eval(session=sess)
  
      Args:
        session: The session to be installed as the default session.
  
      Returns:
        A context manager for the default session.
      """
      return _default_session_stack.get_controller(session)
  
file_path: tensorflow/tensorflow/python/framework/stack.py
imports: from collections.abc import Iterator
  import threading
  from typing import Generic, Optional, TypeVar
  from tensorflow.python.util import tf_contextlib
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 1 for calling a global function with example usage: default_session(session) and returns: _default_session_stack