| 116 | |
| 117 | |
| 118 | class Process: |
| 119 | def __init__(self, transport, protocol, loop): |
| 120 | self._transport = transport |
| 121 | self._protocol = protocol |
| 122 | self._loop = loop |
| 123 | self.stdin = protocol.stdin |
| 124 | self.stdout = protocol.stdout |
| 125 | self.stderr = protocol.stderr |
| 126 | self.pid = transport.get_pid() |
| 127 | |
| 128 | def __repr__(self): |
| 129 | return f'<{self.__class__.__name__} {self.pid}>' |
| 130 | |
| 131 | @property |
| 132 | def returncode(self): |
| 133 | return self._transport.get_returncode() |
| 134 | |
| 135 | async def wait(self): |
| 136 | """Wait until the process exit and return the process return code.""" |
| 137 | return await self._transport._wait() |
| 138 | |
| 139 | def send_signal(self, signal): |
| 140 | self._transport.send_signal(signal) |
| 141 | |
| 142 | def terminate(self): |
| 143 | self._transport.terminate() |
| 144 | |
| 145 | def kill(self): |
| 146 | self._transport.kill() |
| 147 | |
| 148 | async def _feed_stdin(self, input): |
| 149 | debug = self._loop.get_debug() |
| 150 | try: |
| 151 | if input is not None: |
| 152 | self.stdin.write(input) |
| 153 | if debug: |
| 154 | logger.debug( |
| 155 | '%r communicate: feed stdin (%s bytes)', self, len(input)) |
| 156 | |
| 157 | await self.stdin.drain() |
| 158 | except (BrokenPipeError, ConnectionResetError) as exc: |
| 159 | # communicate() ignores BrokenPipeError and ConnectionResetError. |
| 160 | # write() and drain() can raise these exceptions. |
| 161 | if debug: |
| 162 | logger.debug('%r communicate: stdin got %r', self, exc) |
| 163 | |
| 164 | if debug: |
| 165 | logger.debug('%r communicate: close stdin', self) |
| 166 | self.stdin.close() |
| 167 | |
| 168 | async def _noop(self): |
| 169 | return None |
| 170 | |
| 171 | async def _read_stream(self, fd): |
| 172 | transport = self._transport.get_pipe_transport(fd) |
| 173 | if fd == 2: |
| 174 | stream = self.stderr |
| 175 | else: |
no outgoing calls
no test coverage detected
searching dependent graphs…