Spaces:
Runtime error

flux-lora-trainer-space / src /logging_utils.py
Dwitee Krishna Panda
Initial commit: FLUX.1-dev LoRA trainer Space
9e62b86
Raw History Blame Contribute Delete
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)