summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-11-17 01:20:35 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-11-17 01:20:35 -0500
commit697ff1ae39e8ec3f1f1a1b9a36d68c66e8d286b2 (patch)
tree7b2dde5cdf7260ac48d104cd2b91d9f4753fe058
parentb7b179a87623409e031753e0c0c9827251cf75ef (diff)
downloadcmd2-git-697ff1ae39e8ec3f1f1a1b9a36d68c66e8d286b2.tar.gz
Fixed bug where pipe processes were not being stopped by Ctrl-C on Linux/Mac
-rw-r--r--CHANGELOG.md2
-rw-r--r--cmd2/utils.py7
2 files changed, 6 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d71a2d0a..630f6892 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,6 @@
## 0.9.21 (TBD, 2019)
+* Bug Fixes
+ * Fixed bug where pipe processes were not being stopped by Ctrl-C on Linux/Mac
* Enhancements
* Added `read_input()` function that is used to read from stdin. Unlike the Python built-in `input()`, it also has
an argument to disable tab completion while input is being entered.
diff --git a/cmd2/utils.py b/cmd2/utils.py
index 88fbc1da..e3d54ffe 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -520,10 +520,11 @@ class ProcReader(object):
"""Send a SIGINT to the process similar to if <Ctrl>+C were pressed."""
import signal
if sys.platform.startswith('win'):
- signal_to_send = signal.CTRL_C_EVENT
+ self._proc.send_signal(signal.CTRL_C_EVENT)
else:
- signal_to_send = signal.SIGINT
- self._proc.send_signal(signal_to_send)
+ # Since cmd2 uses shell=True in its Popen calls, we need to send the SIGINT to
+ # the whole process group to make sure it propagates further than the shell
+ os.killpg(os.getpgid(self._proc.pid), signal.SIGINT)
def terminate(self) -> None:
"""Terminate the process"""