| 74 | self._process_chunk(b"", final=True) |
| 75 | |
| 76 | def _process_chunk(self, s, final=False): |
| 77 | s = self._decoder.decode(s, final=final) |
| 78 | if len(s) == 0: |
| 79 | return |
| 80 | |
| 81 | try: |
| 82 | launcher.channel.send_event( |
| 83 | "output", {"category": self.category, "output": s.replace("\r\n", "\n")} |
| 84 | ) |
| 85 | except Exception: |
| 86 | pass # channel to adapter is already closed |
| 87 | |
| 88 | if self._stream is None: |
| 89 | return |
| 90 | |
| 91 | try: |
| 92 | s, _ = self._encode(s, "surrogateescape") |
| 93 | size = len(s) |
| 94 | i = 0 |
| 95 | while i < size: |
| 96 | written = self._stream.write(s[i:]) |
| 97 | self._stream.flush() |
| 98 | if written == 0: |
| 99 | # This means that the output stream was closed from the other end. |
| 100 | # Do the same to the debuggee, so that it knows as well. |
| 101 | os.close(self._fd) |
| 102 | self._fd = None |
| 103 | break |
| 104 | i += written |
| 105 | except Exception: |
| 106 | log.swallow_exception("Error printing {0!r} to {1}", s, self.category) |
| 107 | |
| 108 | |
| 109 | def wait_for_remaining_output(): |