Skip to content

Commit

Permalink
Merge pull request #15 from gpetretto/develop
Browse files Browse the repository at this point in the history
update shell io
  • Loading branch information
davidwaroquiers authored Jul 4, 2023
2 parents 20ff3ae + f0a9e77 commit 28edf7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/qtoolkit/host/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ def execute(self, command: str | list[str], workdir: str | Path | None = None):
exit_code : int
Exit code of the command.
"""

if isinstance(command, (list, tuple)):
command = " ".join(command)

# TODO: check here if we use the context manager. What happens if we provide the
# connection from outside (not through a config) and we want to keep it alive ?

Expand Down
2 changes: 1 addition & 1 deletion src/qtoolkit/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
from qtoolkit.io.shell import ShellIO, ShellState
from qtoolkit.io.slurm import SlurmIO, SlurmState

scheduler_mapping = {"slurm": SlurmIO, "pbs": PBSIO}
scheduler_mapping = {"slurm": SlurmIO, "pbs": PBSIO, "shell": ShellIO}
10 changes: 8 additions & 2 deletions src/qtoolkit/io/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def qstate(self) -> QState:

class ShellIO(BaseSchedulerIO):
header_template: str = """
exec > $${qout_path}
exec 2> $${qerr_path}
echo $${job_name}
$${qverbatim}
"""

Expand Down Expand Up @@ -200,8 +204,10 @@ def parse_jobs_list_output(self, exit_code, stdout, stderr) -> list[QJob]:
if isinstance(stderr, bytes):
stderr = stderr.decode()

if exit_code != 0:
msg = f"command ps failed: {stderr}"
# if asking only for pid that are not running the exit code is != 0,
# so check also on stderr for failing
if exit_code != 0 and stderr.strip():
msg = f"command ps failed: stdout: {stdout}. stderr: {stderr}"
raise CommandFailedError(msg)

jobs_list = []
Expand Down

0 comments on commit 28edf7e

Please sign in to comment.