Merge pull request #8523 from nsoranzo/jobs_runners_kill

Small cleanup for job runners kill
This commit is contained in:
Nicola Soranzo
2019-08-27 20:45:24 +01:00
committed by GitHub
4 changed files with 16 additions and 11 deletions
+8 -3
View File
@@ -5,6 +5,7 @@ import datetime
import errno
import logging
import os
import signal
import subprocess
import tempfile
import threading
@@ -92,6 +93,10 @@ class LocalJobRunner(BaseJobRunner):
stdout_file = tempfile.NamedTemporaryFile(mode='wb+', suffix='_stdout', dir=job_wrapper.working_directory)
stderr_file = tempfile.NamedTemporaryFile(mode='wb+', suffix='_stderr', dir=job_wrapper.working_directory)
log.debug('(%s) executing job script: %s' % (job_id, command_line))
# The preexec_fn argument of Popen() is used to call os.setpgrp() in
# the child process just before the child is executed. This will set
# the PGID of the child process to its PID (i.e. ensures that it is
# the root of its own process group instead of Galaxy's one).
proc = subprocess.Popen(args=command_line,
shell=True,
cwd=job_wrapper.working_directory,
@@ -161,7 +166,7 @@ class LocalJobRunner(BaseJobRunner):
if not self._check_pid(pid):
log.warning("stop_job(): %s: PID %d was already dead or can't be signaled" % (job.id, pid))
return
for sig in [15, 9]:
for sig in [signal.SIGTERM, signal.SIGKILL]:
try:
os.killpg(pid, sig)
except OSError as e:
@@ -216,10 +221,10 @@ class LocalJobRunner(BaseJobRunner):
return False
def _terminate(self, proc):
os.killpg(proc.pid, 15)
os.killpg(proc.pid, signal.SIGTERM)
sleep(1)
if proc.poll() is None:
os.killpg(proc.pid, 9)
os.killpg(proc.pid, signal.SIGKILL)
return proc.wait() # reap
def _handle_container(self, job_wrapper, proc):
+3 -2
View File
@@ -3,7 +3,8 @@ This module and its submodules contains utilities for running external
processes and interfacing with job managers. This module should contain
functionality shared between Galaxy and the Pulsar.
"""
from galaxy.util.bunch import Bunch
from .kill import kill_pid
__all__ = ('kill_pid', 'Bunch')
__all__ = (
'kill_pid',
)
@@ -8,11 +8,9 @@ from time import sleep
import six
from ..shell import BaseShellExec
from ....util import (
Bunch,
kill_pid
)
from galaxy.util.bunch import Bunch
from . import BaseShellExec
from ....util import kill_pid
log = getLogger(__name__)
+2 -1
View File
@@ -1,4 +1,5 @@
import os
import signal
import subprocess
from platform import system
from time import sleep
@@ -55,7 +56,7 @@ def __kill_posix(pid):
return False
if __check_pid():
for sig in [15, 9]:
for sig in [signal.SIGTERM, signal.SIGKILL]:
try:
os.killpg(pid, sig)
except OSError: