MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / _reader_thread_func

Method _reader_thread_func

cmd2/utils.py:582–603  ·  view source on GitHub ↗

Thread function that reads a stream from the process. :param read_stdout: if True, then this thread deals with stdout. Otherwise it deals with stderr.

(self, read_stdout: bool)

Source from the content-addressed store, hash-verified

580 self._write_bytes(self._stderr, err)
581
582 def _reader_thread_func(self, read_stdout: bool) -> None:
583 """Thread function that reads a stream from the process.
584
585 :param read_stdout: if True, then this thread deals with stdout. Otherwise it deals with stderr.
586 """
587 if read_stdout:
588 read_stream = self._proc.stdout
589 write_stream = self._stdout
590 else:
591 read_stream = self._proc.stderr
592 write_stream = self._stderr
593
594 # The thread should have been started only if this stream was a pipe
595 if read_stream is None:
596 raise ValueError("read_stream is None")
597
598 # Run until process completes
599 while self._proc.poll() is None:
600 available = read_stream.peek() # type: ignore[attr-defined]
601 if available:
602 read_stream.read(len(available))
603 self._write_bytes(write_stream, available)
604
605 @staticmethod
606 def _write_bytes(stream: StdSim | TextIO, to_write: bytes | str) -> None:

Callers

nothing calls this directly

Calls 2

_write_bytesMethod · 0.95
readMethod · 0.80

Tested by

no test coverage detected