Skip to content

add a basic example for getting the jobinfo #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions examples/job_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from pythonlsf import lsf


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

# 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_single_job_info(int(id))

print(f"job id: {job_info.jobId}\njob name: {job_info.jName}\n"
f"status: {job_info.status:#x}")