From 43120e3c88019f249d979438f432ce238c9c7bb1 Mon Sep 17 00:00:00 2001 From: Yuhao Wang Date: Wed, 23 Dec 2020 23:23:47 +0800 Subject: [PATCH] fix: stop process bug --- task/models.py | 2 +- task/utils.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/task/models.py b/task/models.py index bab9c77..a130843 100644 --- a/task/models.py +++ b/task/models.py @@ -99,7 +99,7 @@ def __str__(self): return self.task.name + '-' + str(self.index) def kill(self): - os.kill(self.pid, signal.SIGKILL) + os.kill(self.pid, signal.SIGINT) def delete_log_file(self): if os.path.isfile(self.log_file_path): diff --git a/task/utils.py b/task/utils.py index ecbc439..3c77835 100644 --- a/task/utils.py +++ b/task/utils.py @@ -19,9 +19,9 @@ def generate_ssh_cmd(host, user, exec_cmd, private_key_path=None): exec_cmd = exec_cmd.replace('$', '\\$') if private_key_path is None: - cmd = "ssh -o StrictHostKeyChecking=no {}@{} \"{}\"".format(user, host, exec_cmd) + cmd = "ssh -tt -o StrictHostKeyChecking=no {}@{} \"{}\"".format(user, host, exec_cmd) else: - cmd = "ssh -o StrictHostKeyChecking=no -i {} {}@{} \"{}\"".format(private_key_path, user, host, exec_cmd) + cmd = "ssh -tt -o StrictHostKeyChecking=no -i {} {}@{} \"{}\"".format(private_key_path, user, host, exec_cmd) return cmd @@ -32,7 +32,7 @@ def __init__(self, user, host, cmd, workspace="~", private_key_path=None, output if output_file is not None: self.output_file = output_file with open(self.output_file, "wb") as out: - self.proc = subprocess.Popen(self.cmd, shell=True, stdout=out, stderr=out, bufsize=1) + self.proc = subprocess.Popen(self.cmd, shell=True, stdin=subprocess.PIPE, stdout=out, stderr=out, bufsize=1) else: self.proc = subprocess.Popen(self.cmd, shell=True) @@ -41,7 +41,8 @@ def pid(self): def kill(self): # os.killpg(os.getpgid(self.proc.pid), signal.SIGKILL) - os.kill(self.proc.pid, signal.SIGKILL) + # os.kill(self.proc.pid, signal.SIGKILL) + self.proc.send_signal(signal.SIGINT) def get_return_code(self): self.proc.wait()