Files
devplacepy/devplacepy/services/devii/tasks/context.py
T

23 lines
434 B
Python
Raw Normal View History

2026-07-26 16:45:38 +02:00
# retoor <retoor@molodetz.nl>
from __future__ import annotations
import contextvars
from contextlib import contextmanager
from typing import Iterator
_TASK_RUN = contextvars.ContextVar("devii_task_run", default=False)
def in_task_run() -> bool:
return _TASK_RUN.get()
@contextmanager
def task_run_scope() -> Iterator[None]:
token = _TASK_RUN.set(True)
try:
yield
finally:
_TASK_RUN.reset(token)