summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/cmd2.py8
-rw-r--r--cmd2/utils.py5
2 files changed, 9 insertions, 4 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 579d462a..e7f0c934 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -1659,8 +1659,8 @@ class Cmd(cmd.Cmd):
:param frame
"""
if self.cur_pipe_proc_reader is not None:
- # Terminate the current pipe process
- self.cur_pipe_proc_reader.terminate()
+ # Pass the SIGINT to the current pipe process
+ self.cur_pipe_proc_reader.send_sigint()
# Check if we are allowed to re-raise the KeyboardInterrupt
if not self.sigint_protection:
@@ -1933,8 +1933,8 @@ class Cmd(cmd.Cmd):
# We want Popen to raise an exception if it fails to open the process. Thus we don't set shell to True.
try:
# Set options to not forward signals to the pipe process. If a Ctrl-C event occurs,
- # our sigint handler terminate the most recent pipe process. This makes sure
- # pipe processes close in the right order (most recent first).
+ # our sigint handler will forward it only to the most recent pipe process. This makes
+ # sure pipe processes close in the right order (most recent first).
if sys.platform == 'win32':
creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
start_new_session = False
diff --git a/cmd2/utils.py b/cmd2/utils.py
index a81a369f..e4da938d 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -404,6 +404,11 @@ class ProcReader(object):
if self._proc.stderr is not None:
self._err_thread.start()
+ def send_sigint(self) -> None:
+ """Send a SIGINT to the process"""
+ import signal
+ self._proc.send_signal(signal.SIGINT)
+
def terminate(self) -> None:
"""Terminate the process"""
self._proc.terminate()