20 lines
427 B
Python
20 lines
427 B
Python
from __future__ import annotations
|
|
|
|
import io
|
|
import queue
|
|
|
|
|
|
class _QueueWriter(io.TextIOBase):
|
|
"""Redirect sys.stdout / sys.stderr into a Queue for the Logs panel."""
|
|
|
|
def __init__(self, q: queue.Queue[str]) -> None:
|
|
self._q = q
|
|
|
|
def write(self, text: str) -> int: # type: ignore[override]
|
|
if text:
|
|
self._q.put(text)
|
|
return len(text)
|
|
|
|
def flush(self) -> None:
|
|
pass
|