| 48 | timeout: int = 300 |
| 49 | |
| 50 | def __exit__(self, exc_type, exc_value, traceback): |
| 51 | # Kill the child process by closing stdin, not via SIGKILL, so it has |
| 52 | # a chance to drain logs. |
| 53 | try: |
| 54 | if self.proc.stdin: |
| 55 | self.proc.stdin.close() |
| 56 | except AttributeError: |
| 57 | # FakeProcess doesn't have a stdin attribute (tests) |
| 58 | self.proc.terminate() |
| 59 | |
| 60 | try: |
| 61 | self._wait() |
| 62 | except Exception: # Including KeyboardInterrupt, wait handled that. |
| 63 | self.proc.kill() |
| 64 | # We don't call proc.wait() again as proc.__exit__ does that for us. |
| 65 | raise |
| 66 | |
| 67 | def _wait(self): |
| 68 | # avoids raise-within-try (TRY301) |