MCPcopy Index your code
hub / github.com/bugy/script-server / pipe_process_output

Method pipe_process_output

src/execution/process_pty.py:69–148  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

67 self.process.wait()
68
69 def pipe_process_output(self):
70 utf8_stream = self.encoding.lower() == 'utf-8'
71
72 buffer = b''
73
74 try:
75 while True:
76 finished = False
77 wait_new_output = False
78
79 max_read_bytes = 1024
80
81 data = buffer
82 buffer = b''
83
84 if self.is_finished():
85 while True:
86 try:
87 chunk = os.read(self.pty_master, max_read_bytes)
88 if not chunk:
89 break
90 data += chunk
91
92 except BlockingIOError:
93 break
94
95 finished = True
96
97 else:
98 try:
99 data += os.read(self.pty_master, max_read_bytes)
100 if data.endswith(b"\r"):
101 data += os.read(self.pty_master, 1)
102
103 if utf8_stream and data:
104 while data[len(data) - 1] >= 127:
105 next_byte = os.read(self.pty_master, 1)
106 if not next_byte:
107 break
108
109 data += next_byte
110 except BlockingIOError:
111 if self.is_finished():
112 finished = True
113
114 if not data:
115 wait_new_output = True
116
117 if utf8_stream and data:
118 while data and data[-1] >= 127:
119 buffer = bytes([data[-1]]) + buffer
120 data = data[:-1]
121
122 if data:
123 try:
124 output_text = encoding_utils.decode(data, self.encoding)
125 self._write_script_output(output_text)
126 except UnicodeDecodeError:

Callers

nothing calls this directly

Calls 5

readMethod · 0.80
_write_script_outputMethod · 0.80
is_finishedMethod · 0.45
killMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected