From cc53589060dde5ebf5644c7c506d43073d989868 Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" Date: Tue, 15 Feb 2022 10:47:19 -0800 Subject: [PATCH 1/3] python: return JobID from flux.job.submit Problem: The Flux jobid returned from job.submit() or SubmitFuture.get_id() is an int, when it would be much more convenient to return an instance of the JobID class. Return a JobID object from job.submit_get_id() so that SubmitFuture.get_id() and job.submit() return JobID instead of int. Fixes #3614 --- src/bindings/python/flux/job/submit.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bindings/python/flux/job/submit.py b/src/bindings/python/flux/job/submit.py index 1aaddedafcf8..e7009cc87b0a 100644 --- a/src/bindings/python/flux/job/submit.py +++ b/src/bindings/python/flux/job/submit.py @@ -12,6 +12,7 @@ from flux import constants from flux.util import check_future_error from flux.future import Future +from flux.job import JobID from flux.job.Jobspec import _convert_jobspec_arg_to_string from flux.job._wrapper import _RAW as RAW from _flux._core import ffi, lib @@ -89,14 +90,14 @@ def submit_get_id(future): :param future: a Flux future object returned by job.submit_async() :type future: Future :returns: job ID - :rtype: int + :rtype: JobID """ if future is None or future == ffi.NULL: raise EnvironmentError(errno.EINVAL, "future must not be None/NULL") future.wait_for() # ensure the future is fulfilled jobid = ffi.new("flux_jobid_t[1]") RAW.submit_get_id(future, jobid) - return int(jobid[0]) + return JobID(jobid[0]) def submit( From 24ff5a7f18cfd1b141a02d7cdce59119e523fc18 Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" Date: Tue, 15 Feb 2022 10:52:58 -0800 Subject: [PATCH 2/3] flux-mini: remove unnecessary use of JobID() Problem: The JobID() constructor is used in flux-mini.py to return a JobID object from the return value of flux.job.SubmitFuture.get_id(), but this function already returns a JobID object. Remove unnecessary calls to JobID(). --- src/cmd/flux-mini.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/flux-mini.py b/src/cmd/flux-mini.py index 4db961398255..80a1b3a58495 100755 --- a/src/cmd/flux-mini.py +++ b/src/cmd/flux-mini.py @@ -26,7 +26,7 @@ import flux from flux import job -from flux.job import JobspecV1, JobID +from flux.job import JobspecV1 from flux import util from flux import debugged from flux.idset import IDset @@ -675,7 +675,7 @@ def submit_async(self, args, jobspec=None): ) def submit(self, args, jobspec=None): - return JobID(self.submit_async(args, jobspec).get_id()) + return self.submit_async(args, jobspec).get_id() def get_parser(self): return self.parser @@ -938,7 +938,7 @@ def event_watch_cb(self, future, args, jobinfo, label=""): def submit_cb(self, future, args, label=""): try: - jobid = JobID(future.get_id()) + jobid = future.get_id() if not args.quiet: print(jobid, file=args.stdout) except OSError as exc: From fe2dbce44bbf2b0690754687a82caf689cf6204d Mon Sep 17 00:00:00 2001 From: "Mark A. Grondona" Date: Tue, 15 Feb 2022 10:55:42 -0800 Subject: [PATCH 3/3] throughput.py: remove unnecessary use of JobID() Problem: The throughput.py test script uses the JobID constructor to return a JobID object from the flux.job.SubmitFuture.get_id() call, but this function already returns a JobID object. Remove the unnecessary call the JobID(). --- src/test/throughput.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/throughput.py b/src/test/throughput.py index ddb5c420d8db..b2eec392d023 100755 --- a/src/test/throughput.py +++ b/src/test/throughput.py @@ -16,7 +16,7 @@ import flux from flux import job -from flux.job import JobspecV1, JobID +from flux.job import JobspecV1 from flux.progress import Bottombar @@ -155,7 +155,7 @@ def handle_submit(self, args, jobid): def submit_cb(self, future, args): # pylint: disable=broad-except try: - self.handle_submit(args, JobID(future.get_id())) + self.handle_submit(args, future.get_id()) except Exception as exc: print(f"Submission failed: {exc}", file=sys.stderr)