From 8888ad91e58aef6285687ec6fd2d986464f9b728 Mon Sep 17 00:00:00 2001 From: Jiangge Zhang Date: Sat, 11 Oct 2014 17:20:30 +0800 Subject: [PATCH 1/2] Allow to disable 'start_new_session' in Popen. --- honcho/process.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/honcho/process.py b/honcho/process.py index 4d31d82..669c8ef 100644 --- a/honcho/process.py +++ b/honcho/process.py @@ -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, @@ -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) From e97bf4caa7409b97beeade4e84862910d9a2f41e Mon Sep 17 00:00:00 2001 From: Jiangge Zhang Date: Sat, 11 Oct 2014 18:46:11 +0800 Subject: [PATCH 2/2] Ignore interrupt signal in parent process after forking. --- honcho/command.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/honcho/command.py b/honcho/command.py index ce4ba55..0b533ee 100644 --- a/honcho/command.py +++ b/honcho/command.py @@ -3,6 +3,7 @@ import logging import os import sys +import signal from collections import defaultdict from pkg_resources import iter_entry_points @@ -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)