Thread-safe log buffer for a single evaluator invocation.
All oa.log() calls within the same evaluator call write to the same
buffer, even from child threads (when properly propagated via
:func:get_log_context / :func:set_log_context). Writes are
serialized with a lock so concurrent threads never interleave.
Source code in gepa/optimize_anything.py
| def __init__(self) -> None:
self._buffer = io.StringIO()
self._lock = threading.Lock()
|
Functions
write(text: str) -> None
Source code in gepa/optimize_anything.py
| def write(self, text: str) -> None:
with self._lock:
self._buffer.write(text)
|
drain() -> str
Drain and return all accumulated text, leaving the buffer empty.
Source code in gepa/optimize_anything.py
| def drain(self) -> str:
"""Drain and return all accumulated text, leaving the buffer empty."""
with self._lock:
old = self._buffer
text = old.getvalue()
old.close()
self._buffer = io.StringIO()
return text
|