Skip to main content
Version: 0.3.x

StdoutWrapper

ClassPrivateContextSource

with syncstream.webtools.StdoutWrapper():
...

A wrapper for ensuring that the stdout is always directed to the same position.

danger

This class was designed from scratch. However, its functionality has been fully covered by contextlib.redirect_stdout(...) and contextlib.redirect_stdout(...). Therefore, users should not use this context in any case.

This document is only used for archiving what was done in this implementation.

Arguments​

No argument is needed.

Example​

Redirect stdout to buffer​

use_stdout_context.py
import sys
import syncstream
from syncstream.webtools import StdoutWrapper

buffer = syncstream.LineBuffer(10)
with StdoutWrapper():
sys.stdout = buffer
for i in range(20):
print(f'Message "{i:02d}".')
print('No line break.', end='')

messages = buffer.read()
for mitem in messages:
print(mitem)