Download llm_panda/execution/cancellation.py from C2-151/Robot: direct link, hf CLI and curl.
- Browser
- Download file 761 Bytes
-
https://huggingface.co/spaces/C2-151/Robot/resolve/main/llm_panda/execution/cancellation.py
- Command line
-
hf download hf://spaces/C2-151/Robot/llm_panda/execution/cancellation.py
-
curl -L -o cancellation.py https://huggingface.co/spaces/C2-151/Robot/resolve/main/llm_panda/execution/cancellation.py
761 Bytes
| """Cooperative cancellation primitives for interruptible robot execution.""" | |
| from __future__ import annotations | |
| import threading | |
| class ExecutionInterrupted(RuntimeError): | |
| """Raised at a safe checkpoint after a newer command supersedes a task.""" | |
| class CancellationToken: | |
| """Thread-safe, dependency-free cancellation token.""" | |
| def __init__(self): | |
| self._event = threading.Event() | |
| self.reason = "" | |
| def request(self, reason: str = "superseded") -> None: | |
| self.reason = reason | |
| self._event.set() | |
| def requested(self) -> bool: | |
| return self._event.is_set() | |
| def checkpoint(self) -> None: | |
| if self.requested: | |
| raise ExecutionInterrupted(self.reason or "interrupted") | |