diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-20 14:24:47 -0400 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-20 14:24:47 -0400 |
| commit | 023acec19eb516dcb3b57ae2b5197e1f80af97d7 (patch) | |
| tree | 7adec8f5a55d23f16669b21fae9511d498ccbedb /cmd2/utils.py | |
| parent | da0f95d72656b46b374d66948c68d4055fed218c (diff) | |
| download | cmd2-git-023acec19eb516dcb3b57ae2b5197e1f80af97d7.tar.gz | |
Handled issue where nested pipe processes were not being closed in the right order upon SIGINT events
Diffstat (limited to 'cmd2/utils.py')
| -rw-r--r-- | cmd2/utils.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index 2db6a267..29ae332a 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -345,7 +345,8 @@ class StdSim(object): """Clear the internal contents""" self.buffer.byte_buf = b'' - def isatty(self) -> bool: + @staticmethod + def isatty() -> bool: """StdSim will never be considered an interactive stream""" return False @@ -403,9 +404,10 @@ class ProcReader(object): if self._proc.stderr is not None: self._err_thread.start() - def terminate(self) -> None: - """Terminates the process being run""" - self._proc.terminate() + def send_sigint(self) -> None: + """Send a SIGINT to the process""" + import signal + self._proc.send_signal(signal.SIGINT) def wait(self) -> None: """Wait for the process to finish""" @@ -452,7 +454,11 @@ class ProcReader(object): :param stream: the stream being written to :param to_write: the bytes being written """ - if 'b' in stream.mode: - stream.write(to_write) - else: - stream.buffer.write(to_write) + try: + if 'b' in stream.mode: + stream.write(to_write) + else: + stream.buffer.write(to_write) + except BrokenPipeError: + # This occurs if output is being piped to a process that closed + pass |
