(self, input, endtime, orig_timeout)
| 1619 | |
| 1620 | |
| 1621 | def _communicate(self, input, endtime, orig_timeout): |
| 1622 | # Start reader threads feeding into a list hanging off of this |
| 1623 | # object, unless they've already been started. |
| 1624 | if self.stdout and not hasattr(self, "_stdout_buff"): |
| 1625 | self._stdout_buff = [] |
| 1626 | self.stdout_thread = \ |
| 1627 | threading.Thread(target=self._readerthread, |
| 1628 | args=(self.stdout, self._stdout_buff)) |
| 1629 | self.stdout_thread.daemon = True |
| 1630 | self.stdout_thread.start() |
| 1631 | if self.stderr and not hasattr(self, "_stderr_buff"): |
| 1632 | self._stderr_buff = [] |
| 1633 | self.stderr_thread = \ |
| 1634 | threading.Thread(target=self._readerthread, |
| 1635 | args=(self.stderr, self._stderr_buff)) |
| 1636 | self.stderr_thread.daemon = True |
| 1637 | self.stderr_thread.start() |
| 1638 | |
| 1639 | # Start writer thread to send input to stdin, unless already |
| 1640 | # started. The thread writes input and closes stdin when done, |
| 1641 | # or continues in the background on timeout. |
| 1642 | if self.stdin and not hasattr(self, "_stdin_thread"): |
| 1643 | self._stdin_thread = \ |
| 1644 | threading.Thread(target=self._writerthread, |
| 1645 | args=(input,)) |
| 1646 | self._stdin_thread.daemon = True |
| 1647 | self._stdin_thread.start() |
| 1648 | |
| 1649 | # Wait for the writer thread, or time out. If we time out, the |
| 1650 | # thread remains writing and the fd left open in case the user |
| 1651 | # calls communicate again. |
| 1652 | if hasattr(self, "_stdin_thread"): |
| 1653 | self._stdin_thread.join(self._remaining_time(endtime)) |
| 1654 | if self._stdin_thread.is_alive(): |
| 1655 | raise TimeoutExpired(self.args, orig_timeout) |
| 1656 | |
| 1657 | # Wait for the reader threads, or time out. If we time out, the |
| 1658 | # threads remain reading and the fds left open in case the user |
| 1659 | # calls communicate again. |
| 1660 | if self.stdout is not None: |
| 1661 | self.stdout_thread.join(self._remaining_time(endtime)) |
| 1662 | if self.stdout_thread.is_alive(): |
| 1663 | raise TimeoutExpired(self.args, orig_timeout) |
| 1664 | if self.stderr is not None: |
| 1665 | self.stderr_thread.join(self._remaining_time(endtime)) |
| 1666 | if self.stderr_thread.is_alive(): |
| 1667 | raise TimeoutExpired(self.args, orig_timeout) |
| 1668 | |
| 1669 | # Collect the output from and close both pipes, now that we know |
| 1670 | # both have been read successfully. |
| 1671 | stdout = None |
| 1672 | stderr = None |
| 1673 | if self.stdout: |
| 1674 | stdout = self._stdout_buff |
| 1675 | self.stdout.close() |
| 1676 | if self.stderr: |
| 1677 | stderr = self._stderr_buff |
| 1678 | self.stderr.close() |
no test coverage detected