Skip to content

Commit

Permalink
fix: give detailed error message when ps is not installed
Browse files Browse the repository at this point in the history
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
  • Loading branch information
njzjz authored Aug 20, 2024
1 parent c8d2114 commit 57e15d3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions dpdispatcher/machines/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@


class Shell(Machine):
def bind_context(self, context):
super().bind_context(context)
self._has_ps = None

def gen_script(self, job):
shell_script = super().gen_script(job)
return shell_script
Expand Down Expand Up @@ -72,6 +76,15 @@ def check_status(self, job):
if job_id == "":
return JobStatus.unsubmitted

if self._has_ps is None:
ret, stdin, stdout, stderr = self.context.block_call("which ps")
if ret != 0:
err_str = stderr.read().decode("utf-8")
raise RuntimeError(
"ps command is not found. Consider installing it using `apt-get install procps` or `yum install procps`\nerror message:%s\nreturn code %d\n"
% (err_str, ret)
)
self._has_ps = True
# mark defunct process as terminated
ret, stdin, stdout, stderr = self.context.block_call(
f"if ps -p {job_id} > /dev/null && ! (ps -o command -p {job_id} | grep defunct >/dev/null) ; then echo 1; fi"
Expand Down

0 comments on commit 57e15d3

Please sign in to comment.