MCPcopy Create free account
hub / github.com/pallets/quart / copy_current_app_context

Function copy_current_app_context

src/quart/ctx.py:350–375  ·  view source on GitHub ↗

Share the current app context with the function decorated. The app context is local per task and hence will not be available in any other task. This decorator can be used to make the context available, .. code-block:: python @copy_current_app_context async def with

(func: Callable)

Source from the content-addressed store, hash-verified

348
349
350def copy_current_app_context(func: Callable) -> Callable:
351 """Share the current app context with the function decorated.
352
353 The app context is local per task and hence will not be available
354 in any other task. This decorator can be used to make the context
355 available,
356
357 .. code-block:: python
358
359 @copy_current_app_context
360 async def within_context() -> None:
361 name = current_app.name
362 ...
363
364 """
365 if not has_app_context():
366 raise RuntimeError("Attempt to copy app context outside of a app context")
367
368 app_context = _cv_app.get().copy()
369
370 @wraps(func)
371 async def wrapper(*args: Any, **kwargs: Any) -> Any:
372 async with app_context:
373 return await app_context.app.ensure_async(func)(*args, **kwargs)
374
375 return wrapper
376
377
378def copy_current_request_context(func: Callable) -> Callable:

Callers 1

Calls 3

has_app_contextFunction · 0.85
copyMethod · 0.45
getMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…