code: def copy_current_request_context(f: t.Callable) -> t.Callable:
      """A helper function that decorates a function to retain the current
      request context.  This is useful when working with greenlets.  The moment
      the function is decorated a copy of the request context is created and
      then pushed when the function is called.  The current session is also
      included in the copied request context.
  
      Example::
  
          import gevent
          from flask import copy_current_request_context
  
          @app.route('/')
          def index():
              @copy_current_request_context
              def do_some_work():
                  # do some work here, it can access flask.request or
                  # flask.session like you would otherwise in the view function.
                  ...
              gevent.spawn(do_some_work)
              return 'Regular response'
  
      .. versionadded:: 0.10
      """
      ctx = _cv_request.get(None)
  
      if ctx is None:
          raise RuntimeError(
              "'copy_current_request_context' can only be used when a"
              " request context is active, such as in a view function."
          )
  
      ctx = ctx.copy()
  
      def wrapper(*args, **kwargs):
          with ctx:
              return ctx.app.ensure_sync(f)(*args, **kwargs)
  
      return update_wrapper(wrapper, f)
  
imports: from __future__ import annotations
  import contextvars
  import sys
  import typing
  from functools import update_wrapper
  from types import TracebackType
  from werkzeug.exceptions import HTTPException
  from .None import typing
  from .globals import _cv_app
  from .globals import _cv_request
  from .signals import appcontext_popped
  from .signals import appcontext_pushed
label_desc: Use image node_id 2 for calling a global function with example usage: copy_current_request_context(f) and returns: update_wrapper, ctx