MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / communicate

Method communicate

tools/python-3.11.9-amd64/Lib/subprocess.py:1165–1230  ·  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 se

(self, input=None, timeout=None)

Source from the content-addressed store, hash-verified

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

Callers 11

_get_command_stdoutFunction · 0.95
run_cgiMethod · 0.95
run_unittestMethod · 0.95
query_vcvarsallFunction · 0.95
_findLib_ldFunction · 0.95
test_find_on_libpathMethod · 0.95
query_vcvarsallFunction · 0.95
_get_nix_font_pathMethod · 0.95
call_subprocessFunction · 0.95
runFunction · 0.45

Calls 9

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

Tested by 3

run_unittestMethod · 0.76
test_find_on_libpathMethod · 0.76