stream_as_generator

lsst.ts.salobj.stream_as_generator(stream, encoding='utf-8')

Await lines of text from stdin or another input stream.

Example usage:

async for line in stream_as_generator(stream=sys.stdin):
print(f”read {repr(line)}”)
Parameters:
stream : stream

Stream to read, e.g. sys.stdin.

encoding : str or None

Encoding. If provided then decode the line, else return the line as raw bytes.

Returns:
line : str

A line of data, optionally decoded.

Notes

Thanks to http://blog.mathieu-leplatre.info/some-python-3-asyncio-snippets.html