Skip to content

Commit 1720915

Browse files
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 <annabeths111@gmail.com>
1 parent 65fe2f9 commit 1720915

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

examples/job_info.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from pythonlsf import lsf
2+
3+
4+
def get_job_info(jobid: int) -> lsf.jobInfoEnt:
5+
if lsf.lsb_init("job_info") > 0:
6+
print("could not initialise the api")
7+
return
8+
9+
# openjobinfo opens a connection to mbatchd and returns the amount of
10+
# jobs in the connection.
11+
num_jobs_found = lsf.lsb_openjobinfo(jobid, "", "all", "", "", 0x2000)
12+
13+
# make and assign an int pointer to the record of the jobs found
14+
int_ptr = lsf.new_intp()
15+
lsf.intp_assign(int_ptr, num_jobs_found)
16+
17+
# read the info at int_ptr and assign to a python object so we can read it.
18+
job_info = lsf.lsb_readjobinfo(int_ptr)
19+
20+
# close the connection to avoid a memory leak
21+
lsf.lsb_closejobinfo()
22+
23+
return job_info
24+
25+
26+
if __name__ == "__main__":
27+
id = input("enter a job id:\n")
28+
job_info = get_job_info(int(id))
29+
30+
print(f"job id: {job_info.jobId}\njob name: {job_info.jName}\n"
31+
f"status: {job_info.status:#x}")

0 commit comments

Comments
 (0)