From 17209159dab26c98bbe3f5f380c14fbe2fcd4cb8 Mon Sep 17 00:00:00 2001 From: anna-singleton Date: Fri, 11 Nov 2022 13:52:32 +0000 Subject: [PATCH 1/2] add a basic example for getting the jobinfo intended as a very basic example, somewhat of a jumping off point Signed-off-by: Anna Singleton --- examples/job_info.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 examples/job_info.py diff --git a/examples/job_info.py b/examples/job_info.py new file mode 100644 index 0000000..3fd2fc4 --- /dev/null +++ b/examples/job_info.py @@ -0,0 +1,31 @@ +from pythonlsf import lsf + + +def get_job_info(jobid: int) -> lsf.jobInfoEnt: + if lsf.lsb_init("job_info") > 0: + print("could not initialise the api") + return + + # openjobinfo opens a connection to mbatchd and returns the amount of + # jobs in the connection. + num_jobs_found = lsf.lsb_openjobinfo(jobid, "", "all", "", "", 0x2000) + + # make and assign an int pointer to the record of the jobs found + int_ptr = lsf.new_intp() + lsf.intp_assign(int_ptr, num_jobs_found) + + # read the info at int_ptr and assign to a python object so we can read it. + job_info = lsf.lsb_readjobinfo(int_ptr) + + # close the connection to avoid a memory leak + lsf.lsb_closejobinfo() + + return job_info + + +if __name__ == "__main__": + id = input("enter a job id:\n") + job_info = get_job_info(int(id)) + + print(f"job id: {job_info.jobId}\njob name: {job_info.jName}\n" + f"status: {job_info.status:#x}") From 6d9b253653c00f9be9607f71dd78a0c8b4050bed Mon Sep 17 00:00:00 2001 From: anna-singleton Date: Tue, 6 Dec 2022 14:39:43 +0000 Subject: [PATCH 2/2] rename function and add comments specifying for single jobs only Signed-off-by: anna-singleton --- examples/job_info.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/job_info.py b/examples/job_info.py index 3fd2fc4..2779040 100644 --- a/examples/job_info.py +++ b/examples/job_info.py @@ -1,7 +1,12 @@ from pythonlsf import lsf -def get_job_info(jobid: int) -> lsf.jobInfoEnt: +def get_single_job_info(jobid: int) -> lsf.jobInfoEnt: + """ + Get the jobInfoEnt struct for a single lsf job using its jobId + + This function does not work for array jobs, only single jobs + """ if lsf.lsb_init("job_info") > 0: print("could not initialise the api") return @@ -25,7 +30,7 @@ def get_job_info(jobid: int) -> lsf.jobInfoEnt: if __name__ == "__main__": id = input("enter a job id:\n") - job_info = get_job_info(int(id)) + job_info = get_single_job_info(int(id)) print(f"job id: {job_info.jobId}\njob name: {job_info.jName}\n" f"status: {job_info.status:#x}")