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)
| 348 | |
| 349 | |
| 350 | def 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 | |
| 378 | def copy_current_request_context(func: Callable) -> Callable: |
searching dependent graphs…