Skip to content

Commit

Permalink
Interrupt now sends the signal to a process group, like a shell does.
Browse files Browse the repository at this point in the history
  • Loading branch information
noamraph committed Dec 13, 2016
1 parent fb18920 commit 13fd12c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion dreampielib/gui/subprocess_handler.py
Expand Up @@ -260,7 +260,14 @@ def interrupt(self):
if self._popen is None:
raise ValueError("Subprocess not living")
if sys.platform != 'win32':
os.kill(self._popen.pid, signal.SIGINT)
pid = self._popen.pid
if os.getpgid(pid) == pid:
# If the subprocess managed to become a process group leader,
# send the signal to the entire group (this is what happens
# in terminals)
os.killpg(pid, signal.SIGINT)
else:
os.kill(pid, signal.SIGINT)
else:
kernel32 = ctypes.windll.kernel32
CTRL_C_EVENT = 0
Expand Down
4 changes: 4 additions & 0 deletions dreampielib/subprocess/__init__.py
Expand Up @@ -184,6 +184,10 @@ def __init__(self, port):
# Mask SIGINT/Ctrl-C
mask_sigint()

# Become a process group leader
if sys.platform != 'win32':
os.setpgrp()

# Make sys.displayhook change self.last_res
self.last_res = None
sys.displayhook = self.displayhook
Expand Down

0 comments on commit 13fd12c

Please sign in to comment.