Skip to content

Commit 2f55fdd

Browse files
committed
Merge branch 'main' into ci_installer
2 parents 504a957 + 06120fc commit 2f55fdd

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

src/psij/launchers/script_based_launcher.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,7 @@ def is_launcher_failure(self, output: str) -> bool:
204204

205205
def get_launcher_failure_message(self, output: str) -> str:
206206
"""See :func:`~psij.Launcher.get_launcher_failure_message`."""
207-
return '\n'.join(output.split('\n')[:-2])
207+
# If, according to the above, it is a launcher failure, then
208+
# the magic line should not be present (aka, all of the output
209+
# is the failure).
210+
return output

src/psij/launchers/scripts/mpi_launch.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,29 @@ fi
1515

1616
pre_launch
1717

18+
filter_out() {
19+
sed -nE 's/^\[[^]]+\]<stdout>:(.*)/\1/p'
20+
}
21+
22+
filter_err() {
23+
sed -nE 's/^\[[^]]+\]<stderr>:(.*)/\1/p'
24+
}
25+
26+
filter_out_5() {
27+
sed -nE 's/^\[[^]]+\]<stdout>: (.*)/\1/p'
28+
}
29+
30+
filter_err_5() {
31+
sed -nE 's/^\[[^]]+\]<stderr>: (.*)/\1/p'
32+
}
33+
1834
set +e
1935
if [ "$IS_OPENMPI_5" == "1" ]; then
20-
# there is no -q parameter in OMPI 5
21-
mpirun --oversubscribe -n $_PSI_J_PROCESS_COUNT "$@" 1>$_PSI_J_STDOUT 2>$_PSI_J_STDERR <$_PSI_J_STDIN
36+
mpirun --oversubscribe --output TAG -n $_PSI_J_PROCESS_COUNT "$@" \
37+
1> >(filter_out_5 > $_PSI_J_STDOUT) 2> >(filter_err_5 > $_PSI_J_STDERR) <$_PSI_J_STDIN
2238
elif [ "$IS_OPENMPI" == "1" ]; then
23-
mpirun --oversubscribe -q -n $_PSI_J_PROCESS_COUNT "$@" 1>$_PSI_J_STDOUT 2>$_PSI_J_STDERR <$_PSI_J_STDIN
39+
mpirun --oversubscribe --tag-output -q -n $_PSI_J_PROCESS_COUNT "$@" \
40+
1> >(filter_out > "$_PSI_J_STDOUT") 2> >(filter_err > $_PSI_J_STDERR) <$_PSI_J_STDIN
2441
else
2542
mpirun -n $_PSI_J_PROCESS_COUNT "$@" 1>$_PSI_J_STDOUT 2>$_PSI_J_STDERR <$_PSI_J_STDIN
2643
fi

tests/_test_tools.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ def _read_file(path: Optional[Path]) -> str:
2828
if path is None:
2929
return ''
3030

31-
with open(path, 'r') as f:
32-
return f.read()
31+
try:
32+
with open(path, 'r') as f:
33+
return f.read()
34+
except FileNotFoundError:
35+
return '<missing>'
36+
except Exception as ex:
37+
return f'<error: {ex}>'
3338

3439

3540
def assert_completed(job: Job, status: Optional[JobStatus], attached: bool = False) -> None:

tests/test_executor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ def test_simple_job_redirect(execparams: ExecutorTestParams) -> None:
3636
assert contents == '_x_'
3737

3838

39+
def test_stderr_redirect(execparams: ExecutorTestParams) -> None:
40+
_make_test_dir()
41+
with TemporaryDirectory(dir=Path.home() / '.psij' / 'test') as td:
42+
outp = Path(td, 'stderr.txt')
43+
job = Job(JobSpec(executable='/bin/bash', arguments=['-c', 'echo -n _x_ 1>&2'],
44+
stderr_path=outp))
45+
ex = _get_executor_instance(execparams, job)
46+
ex.submit(job)
47+
status = job.wait(timeout=_get_timeout(execparams))
48+
assert_completed(job, status)
49+
f = outp.open("r")
50+
contents = f.read()
51+
f.close()
52+
assert contents == '_x_'
53+
54+
3955
def test_attach(execparams: ExecutorTestParams) -> None:
4056
job1 = Job(JobSpec(executable='/bin/sleep', arguments=['1']))
4157
ex = _get_executor_instance(execparams, job1)

0 commit comments

Comments
 (0)