Skip to content

Commit 697ff1a

Browse files
committed
Fixed bug where pipe processes were not being stopped by Ctrl-C on Linux/Mac
1 parent b7b179a commit 697ff1a

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## 0.9.21 (TBD, 2019)
2+
* Bug Fixes
3+
* Fixed bug where pipe processes were not being stopped by Ctrl-C on Linux/Mac
24
* Enhancements
35
* Added `read_input()` function that is used to read from stdin. Unlike the Python built-in `input()`, it also has
46
an argument to disable tab completion while input is being entered.

cmd2/utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,11 @@ def send_sigint(self) -> None:
520520
"""Send a SIGINT to the process similar to if <Ctrl>+C were pressed."""
521521
import signal
522522
if sys.platform.startswith('win'):
523-
signal_to_send = signal.CTRL_C_EVENT
523+
self._proc.send_signal(signal.CTRL_C_EVENT)
524524
else:
525-
signal_to_send = signal.SIGINT
526-
self._proc.send_signal(signal_to_send)
525+
# Since cmd2 uses shell=True in its Popen calls, we need to send the SIGINT to
526+
# the whole process group to make sure it propagates further than the shell
527+
os.killpg(os.getpgid(self._proc.pid), signal.SIGINT)
527528

528529
def terminate(self) -> None:
529530
"""Terminate the process"""

0 commit comments

Comments
 (0)