Spaces:
Sleeping
Sleeping
Download app/agent/runtime.py from appQQQ/FinDataPilot: direct link, hf CLI and curl.
- Browser
- Download file 954 Bytes
-
https://huggingface.co/spaces/appQQQ/FinDataPilot/resolve/main/app/agent/runtime.py
- Command line
-
hf download hf://spaces/appQQQ/FinDataPilot/app/agent/runtime.py
-
curl -L -o runtime.py https://huggingface.co/spaces/appQQQ/FinDataPilot/resolve/main/app/agent/runtime.py
954 Bytes
| """In-process registry for cancellable live agent runs. | |
| Durable status/event records live in SQLite; this registry only owns the | |
| current task and therefore is intentionally cleared on process restart. | |
| """ | |
| from __future__ import annotations | |
| import asyncio | |
| class ActiveRunRegistry: | |
| def __init__(self) -> None: | |
| self._tasks: dict[str, asyncio.Task[object]] = {} | |
| self._lock = asyncio.Lock() | |
| async def register(self, run_id: str, task: asyncio.Task[object]) -> None: | |
| async with self._lock: | |
| self._tasks[run_id] = task | |
| async def unregister(self, run_id: str) -> None: | |
| async with self._lock: | |
| self._tasks.pop(run_id, None) | |
| async def cancel(self, run_id: str) -> bool: | |
| async with self._lock: | |
| task = self._tasks.get(run_id) | |
| if task is None or task.done(): | |
| return False | |
| task.cancel() | |
| return True | |
| ACTIVE_RUNS = ActiveRunRegistry() | |