Spaces:
Runtime error
Runtime error
Download src/logging_utils.py from dwitee/flux-lora-trainer-space: direct link, hf CLI and curl.
- Browser
- Download file 782 Bytes
-
https://huggingface.co/spaces/dwitee/flux-lora-trainer-space/resolve/main/src/logging_utils.py
- Command line
-
hf download hf://spaces/dwitee/flux-lora-trainer-space/src/logging_utils.py
-
curl -L -o logging_utils.py https://huggingface.co/spaces/dwitee/flux-lora-trainer-space/resolve/main/src/logging_utils.py
782 Bytes
| """Thread-safe log buffer for streaming subprocess output to Gradio.""" | |
| from __future__ import annotations | |
| import threading | |
| from collections import deque | |
| class LogBuffer: | |
| """Append-only, thread-safe log buffer with a maximum line count.""" | |
| def __init__(self, max_lines: int = 5000) -> None: | |
| self._lines: deque[str] = deque(maxlen=max_lines) | |
| self._lock = threading.Lock() | |
| def append(self, line: str) -> None: | |
| with self._lock: | |
| self._lines.append(line) | |
| def get_text(self) -> str: | |
| with self._lock: | |
| return "\n".join(self._lines) | |
| def clear(self) -> None: | |
| with self._lock: | |
| self._lines.clear() | |
| def __len__(self) -> int: | |
| with self._lock: | |
| return len(self._lines) | |