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

Method _communicate

tools/python-3.11.9-amd64/Lib/subprocess.py:1603–1651  ·  view source on GitHub ↗
(self, input, endtime, orig_timeout)

Source from the content-addressed store, hash-verified

1601
1602
1603 def _communicate(self, input, endtime, orig_timeout):
1604 # Start reader threads feeding into a list hanging off of this
1605 # object, unless they've already been started.
1606 if self.stdout and not hasattr(self, "_stdout_buff"):
1607 self._stdout_buff = []
1608 self.stdout_thread = \
1609 threading.Thread(target=self._readerthread,
1610 args=(self.stdout, self._stdout_buff))
1611 self.stdout_thread.daemon = True
1612 self.stdout_thread.start()
1613 if self.stderr and not hasattr(self, "_stderr_buff"):
1614 self._stderr_buff = []
1615 self.stderr_thread = \
1616 threading.Thread(target=self._readerthread,
1617 args=(self.stderr, self._stderr_buff))
1618 self.stderr_thread.daemon = True
1619 self.stderr_thread.start()
1620
1621 if self.stdin:
1622 self._stdin_write(input)
1623
1624 # Wait for the reader threads, or time out. If we time out, the
1625 # threads remain reading and the fds left open in case the user
1626 # calls communicate again.
1627 if self.stdout is not None:
1628 self.stdout_thread.join(self._remaining_time(endtime))
1629 if self.stdout_thread.is_alive():
1630 raise TimeoutExpired(self.args, orig_timeout)
1631 if self.stderr is not None:
1632 self.stderr_thread.join(self._remaining_time(endtime))
1633 if self.stderr_thread.is_alive():
1634 raise TimeoutExpired(self.args, orig_timeout)
1635
1636 # Collect the output from and close both pipes, now that we know
1637 # both have been read successfully.
1638 stdout = None
1639 stderr = None
1640 if self.stdout:
1641 stdout = self._stdout_buff
1642 self.stdout.close()
1643 if self.stderr:
1644 stderr = self._stderr_buff
1645 self.stderr.close()
1646
1647 # All data exchanged. Translate lists into strings.
1648 stdout = stdout[0] if stdout else None
1649 stderr = stderr[0] if stderr else None
1650
1651 return (stdout, stderr)
1652
1653 def send_signal(self, sig):
1654 """Send a signal to the process."""

Callers 1

communicateMethod · 0.95

Calls 15

_stdin_writeMethod · 0.95
_remaining_timeMethod · 0.95
_save_inputMethod · 0.95
_check_timeoutMethod · 0.95
waitMethod · 0.95
_translate_newlinesMethod · 0.95
TimeoutExpiredClass · 0.85
startMethod · 0.45
joinMethod · 0.45
is_aliveMethod · 0.45
closeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected