MCPcopy Create free account
hub / github.com/pyinvoke/invoke / read_proc_output

Method read_proc_output

invoke/runners.py:697–728  ·  view source on GitHub ↗

Iteratively read & decode bytes from a subprocess' out/err stream. :param reader: A literal reader function/partial, wrapping the actual stream object in question, which takes a number of bytes to read, and returns that many bytes (or ``None``).

(self, reader: Callable)

Source from the content-addressed store, hash-verified

695 return Result(**kwargs)
696
697 def read_proc_output(self, reader: Callable) -> Generator[str, None, None]:
698 """
699 Iteratively read & decode bytes from a subprocess' out/err stream.
700
701 :param reader:
702 A literal reader function/partial, wrapping the actual stream
703 object in question, which takes a number of bytes to read, and
704 returns that many bytes (or ``None``).
705
706 ``reader`` should be a reference to either `read_proc_stdout` or
707 `read_proc_stderr`, which perform the actual, platform/library
708 specific read calls.
709
710 :returns:
711 A generator yielding strings.
712
713 Specifically, each resulting string is the result of decoding
714 `read_chunk_size` bytes read from the subprocess' out/err stream.
715
716 .. versionadded:: 1.0
717 """
718 # NOTE: Typically, reading from any stdout/err (local, remote or
719 # otherwise) can be thought of as "read until you get nothing back".
720 # This is preferable over "wait until an out-of-band signal claims the
721 # process is done running" because sometimes that signal will appear
722 # before we've actually read all the data in the stream (i.e.: a race
723 # condition).
724 while True:
725 data = reader(self.read_chunk_size)
726 if not data:
727 break
728 yield self.decode(data)
729
730 def write_our_output(self, stream: IO, string: str) -> None:
731 """

Callers 1

_handle_outputMethod · 0.95

Calls 1

decodeMethod · 0.95

Tested by

no test coverage detected