code: def local_context(**kwargs):
      """
      Attach some key-value pairs to a local context on the current thread for the execution lifetime of the context block.
      Attached keys can then be retrieved with the function ``local_env``.
  
      :param kwargs: key-value pairs to be attached to this context.
      """
      to_restore = {}
      try:
          context = _get_local()
          for k, v in kwargs.items():
              if k in context:
                  to_restore[k] = context[k]
              context[k] = v
          _set_local(context)
          yield
      finally:
          context = (
              _get_local()
          )  # getting a new copy as the context could have been modified in async event loop.
          for k, v in kwargs.items():
              if k in to_restore:
                  context[k] = to_restore[k]
              else:
                  del context[k]
          _set_local(context)
  
imports: from contextlib import contextmanager
  import threading
label_desc: Use image node_id 1 for calling a global function with example usage: local_context() without return types