From 2ece19f1149b32f18783d1398591df5b26440ad8 Mon Sep 17 00:00:00 2001 From: Manavalan Gajapathy Date: Tue, 25 Feb 2020 17:11:12 -0600 Subject: [PATCH 1/2] catches errors when submitting jobs --- slurmpy/slurmpy.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/slurmpy/slurmpy.py b/slurmpy/slurmpy.py index 966e9b0..d4df800 100755 --- a/slurmpy/slurmpy.py +++ b/slurmpy/slurmpy.py @@ -168,14 +168,18 @@ def run(self, command, name_addition=None, cmd_kwargs=None, mid = "--dependency=afternotok:%d" % job_id args.append(mid) args.append(sh.name) - res = subprocess.check_output(args).strip() - print(res, file=sys.stderr) - self.name = n - if not res.startswith(b"Submitted batch"): - return None - j_id = int(res.split()[-1]) - if itry == 1: - job_id = j_id + try: + res = subprocess.check_output(args).strip() + print(res.decode(), file=sys.stderr) + self.name = n + if not res.startswith(b"Submitted batch"): + return None + j_id = int(res.split()[-1]) + if itry == 1: + job_id = j_id + except Exception as e: + print ("\x1B[31;9m" + 'Error submitting job:' + "\x1B[0m\n") + print(e.output.decode()) return job_id From f029d54a0868aa26a4f0cfb745c13282fb6ed9d7 Mon Sep 17 00:00:00 2001 From: Manavalan Gajapathy Date: Wed, 26 Feb 2020 16:23:39 -0600 Subject: [PATCH 2/2] reverts changes except printing res not as binary --- slurmpy/slurmpy.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/slurmpy/slurmpy.py b/slurmpy/slurmpy.py index d4df800..0612d9a 100755 --- a/slurmpy/slurmpy.py +++ b/slurmpy/slurmpy.py @@ -168,18 +168,14 @@ def run(self, command, name_addition=None, cmd_kwargs=None, mid = "--dependency=afternotok:%d" % job_id args.append(mid) args.append(sh.name) - try: - res = subprocess.check_output(args).strip() - print(res.decode(), file=sys.stderr) - self.name = n - if not res.startswith(b"Submitted batch"): - return None - j_id = int(res.split()[-1]) - if itry == 1: - job_id = j_id - except Exception as e: - print ("\x1B[31;9m" + 'Error submitting job:' + "\x1B[0m\n") - print(e.output.decode()) + res = subprocess.check_output(args).strip() + print(res.decode(), file=sys.stderr) + self.name = n + if not res.startswith(b"Submitted batch"): + return None + j_id = int(res.split()[-1]) + if itry == 1: + job_id = j_id return job_id