code: def shield(arg):
      """Wait for a future, shielding it from cancellation.
  
      The statement
  
          task = asyncio.create_task(something())
          res = await shield(task)
  
      is exactly equivalent to the statement
  
          res = await something()
  
      *except* that if the coroutine containing it is cancelled, the
      task running in something() is not cancelled.  From the POV of
      something(), the cancellation did not happen.  But its caller is
      still cancelled, so the yield-from expression still raises
      CancelledError.  Note: If something() is cancelled by other means
      this will still cancel shield().
  
      If you want to completely ignore cancellation (not recommended)
      you can combine shield() with a try/except clause, as follows:
  
          task = asyncio.create_task(something())
          try:
              res = await shield(task)
          except CancelledError:
              res = None
  
      Save a reference to tasks passed to this function, to avoid
      a task disappearing mid-execution. The event loop only keeps
      weak references to tasks. A task that isn't referenced elsewhere
      may get garbage collected at any time, even before it's done.
      """
      inner = _ensure_future(arg)
      if inner.done():
          # Shortcut.
          return inner
      loop = futures._get_loop(inner)
      outer = loop.create_future()
  
      def _inner_done_callback(inner):
          if outer.cancelled():
              if not inner.cancelled():
                  # Mark inner's result as retrieved.
                  inner.exception()
              return
  
          if inner.cancelled():
              outer.cancel()
          else:
              exc = inner.exception()
              if exc is not None:
                  outer.set_exception(exc)
              else:
                  outer.set_result(inner.result())
  
      def _outer_done_callback(outer):
          if not inner.done():
              inner.remove_done_callback(_inner_done_callback)
  
      inner.add_done_callback(_inner_done_callback)
      outer.add_done_callback(_outer_done_callback)
      return outer
  
imports: import concurrent.futures
  import contextvars
  import functools
  import inspect
  import itertools
  import types
  import warnings
  import weakref
  from types import GenericAlias
  from .None import base_tasks
  from .None import coroutines
  from .None import events
  from .None import exceptions
  from .None import futures
  from .coroutines import _is_coroutine
label_desc: Use image node_id 12 for calling a global function with example usage: shield(arg) and returns: outer, inner