Skip to content

Commit

Permalink
fix: stop process bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cnstark committed Dec 23, 2020
1 parent b269279 commit d41e502
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion task/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 5 additions & 4 deletions task/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,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


Expand All @@ -28,7 +28,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)

Expand All @@ -37,7 +37,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()
Expand Down

0 comments on commit d41e502

Please sign in to comment.