mirror of
https://github.com/chidiwilliams/buzz.git
synced 2026-03-14 22:55:46 +01:00
31 lines
570 B
Python
31 lines
570 B
Python
import sys
|
|
from contextlib import contextmanager
|
|
from multiprocessing.connection import Connection
|
|
|
|
|
|
class ConnWriter:
|
|
def __init__(self, conn: Connection):
|
|
self.conn = conn
|
|
|
|
def write(self, s: str):
|
|
self.conn.send(s.strip())
|
|
|
|
|
|
@contextmanager
|
|
def pipe_stderr(conn: Connection):
|
|
sys.stderr = ConnWriter(conn)
|
|
|
|
try:
|
|
yield
|
|
finally:
|
|
sys.stderr = sys.__stderr__
|
|
|
|
|
|
@contextmanager
|
|
def pipe_stdout(conn: Connection):
|
|
sys.stdout = ConnWriter(conn)
|
|
|
|
try:
|
|
yield
|
|
finally:
|
|
sys.stdout = sys.__stdout__
|