Skip to content

Commit

Permalink
Merge pull request #84 from tonyseek/subprocess-interrupt
Browse files Browse the repository at this point in the history
Restrict the child process received interrupt signal. closes #70 #79
  • Loading branch information
slafs committed Oct 16, 2014
2 parents a7d5c1a + e97bf4c commit 000a7e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion honcho/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import sys
import signal
from collections import defaultdict
from pkg_resources import iter_entry_points

Expand Down Expand Up @@ -157,7 +158,9 @@ def command_run(args):
else:
cmd = ' '.join(compat.shellquote(arg) for arg in args.argv)

p = Popen(cmd, stdout=sys.stdout, stderr=sys.stderr)
p = Popen(cmd, stdout=sys.stdout, stderr=sys.stderr,
start_new_session=False)
signal.signal(signal.SIGINT, signal.SIG_IGN)
p.wait()
sys.exit(p.returncode)

Expand Down
10 changes: 6 additions & 4 deletions honcho/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def _send_message(self, data, type='line'):
class Popen(subprocess.Popen):

def __init__(self, cmd, **kwargs):
start_new_session = kwargs.pop('start_new_session', True)
options = {
'stdout': subprocess.PIPE,
'stderr': subprocess.STDOUT,
Expand All @@ -81,9 +82,10 @@ def __init__(self, cmd, **kwargs):
create_new_process_group = 0x00000200
detached_process = 0x00000008
options.update(creationflags=detached_process | create_new_process_group)
elif sys.version_info < (3, 2):
options.update(preexec_fn=os.setsid)
else:
options.update(start_new_session=True)
elif start_new_session:
if sys.version_info < (3, 2):
options.update(preexec_fn=os.setsid)
else:
options.update(start_new_session=True)

super(Popen, self).__init__(cmd, **options)

0 comments on commit 000a7e6

Please sign in to comment.