23 lines
434 B
Python
23 lines
434 B
Python
# 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)
|