Files
dify/api/libs/contextvars.py
T
-LAN-andautofix-ci[bot] 823f40e71f refactor(workflow): adopt Graphon 0.8 execution orchestration (#40277)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-10-19 13:03:56 +00:00

14 lines
480 B
Python

from collections.abc import Generator
from contextlib import ExitStack, contextmanager
from contextvars import Context
@contextmanager
def use_contextvars(context_vars: Context | None) -> Generator[None]:
"""Apply captured bindings and restore the caller's values after cleanup."""
with ExitStack() as stack:
if context_vars is not None:
for var, value in context_vars.items():
stack.callback(var.reset, var.set(value))
yield