Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict the child process received interrupt signal. #84

Merged
merged 2 commits into from
Oct 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)