MCPcopy Index your code
hub / github.com/RustPython/RustPython / communicate

Method communicate

Lib/subprocess.py:1176–1244  ·  view source on GitHub ↗

Interact with process: Send data to stdin and close it. Read data from stdout and stderr, until end-of-file is reached. Wait for process to terminate. The optional "input" argument should be data to be sent to the child process, or None, if no data should be sent to

(self, input=None, timeout=None)

Source from the content-addressed store, hash-verified

1174 raise
1175
1176 def communicate(self, input=None, timeout=None):
1177 """Interact with process: Send data to stdin and close it.
1178 Read data from stdout and stderr, until end-of-file is
1179 reached. Wait for process to terminate.
1180
1181 The optional "input" argument should be data to be sent to the
1182 child process, or None, if no data should be sent to the child.
1183 communicate() returns a tuple (stdout, stderr).
1184
1185 By default, all communication is in bytes, and therefore any
1186 "input" should be bytes, and the (stdout, stderr) will be bytes.
1187 If in text mode (indicated by self.text_mode), any "input" should
1188 be a string, and (stdout, stderr) will be strings decoded
1189 according to locale encoding, or by "encoding" if set. Text mode
1190 is triggered by setting any of text, encoding, errors or
1191 universal_newlines.
1192 """
1193
1194 if self._communication_started and input:
1195 raise ValueError("Cannot send input after starting communication")
1196
1197 # Optimization: If we are not worried about timeouts, we haven't
1198 # started communicating, and we have one or zero pipes, using select()
1199 # or threads is unnecessary.
1200 if (timeout is None and not self._communication_started and
1201 [self.stdin, self.stdout, self.stderr].count(None) >= 2):
1202 stdout = None
1203 stderr = None
1204 if self.stdin:
1205 self._stdin_write(input)
1206 elif self.stdout:
1207 stdout = self.stdout.read()
1208 self.stdout.close()
1209 elif self.stderr:
1210 stderr = self.stderr.read()
1211 self.stderr.close()
1212 self.wait()
1213 else:
1214 if timeout is not None:
1215 endtime = _time() + timeout
1216 else:
1217 endtime = None
1218
1219 try:
1220 stdout, stderr = self._communicate(input, endtime, timeout)
1221 except KeyboardInterrupt:
1222 # https://bugs.python.org/issue25942
1223 # See the detailed comment in .wait().
1224 if timeout is not None:
1225 sigint_timeout = min(self._sigint_wait_secs,
1226 self._remaining_time(endtime))
1227 else:
1228 sigint_timeout = self._sigint_wait_secs
1229 self._sigint_wait_secs = 0 # nothing else should wait.
1230 try:
1231 self._wait(timeout=sigint_timeout)
1232 except TimeoutExpired:
1233 pass

Callers 15

_get_command_stdoutFunction · 0.95
run_cgiMethod · 0.95
run_commandMethod · 0.95
test_refcount_errorsMethod · 0.95
test_stdout_noneMethod · 0.95
test_communicateMethod · 0.95

Calls 10

_stdin_writeMethod · 0.95
waitMethod · 0.95
_communicateMethod · 0.95
_remaining_timeMethod · 0.95
_waitMethod · 0.95
_timeFunction · 0.90
minFunction · 0.85
countMethod · 0.45
readMethod · 0.45
closeMethod · 0.45