Skip to content

Commit a4400da

Browse files
author
Yan Li
committed
add example for query multiple jobs info
1 parent 322936f commit a4400da

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

examples/get_jobs_info.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from pythonlsf import lsf
2+
import sys
3+
4+
def get_job_info(list) :
5+
if lsf.lsb_init("test") > 0:
6+
print("failed to initialize")
7+
return
8+
if len(list) == 0 :
9+
print("no valid job id given")
10+
return
11+
print("request below job's info: {}".format(list))
12+
clusterName = lsf.ls_getclustername()
13+
print("retrieve cluster name : {}".format(clusterName))
14+
query = "jobIds=("
15+
for l in list:
16+
query += l +","
17+
query = query[:-1]
18+
query += ")jobSouceClusterNames=("
19+
for i in range(len(list)):
20+
query += clusterName + ","
21+
query = query[:-1]
22+
query += ") options=" + str(lsf.ALL_JOB) + " "
23+
24+
jobQuery = lsf.jobInfoQuery()
25+
jobQuery.nCols = 10
26+
jobQuery.colIndexs = lsf.buildQueryColIndexs()
27+
28+
jobQuery.query = query
29+
jobQuery.submitExt = lsf.submit_ext()
30+
more = lsf.new_intp()
31+
print("request: {}".format(jobQuery.query))
32+
jobInfoPtr = lsf.jobInfoHeadExt()
33+
jobInfoPtr = lsf.lsb_queryjobinfo_ext_2(jobQuery, clusterName)
34+
foundJob = False
35+
if jobInfoPtr != None :
36+
if jobInfoPtr.jobInfoHead != None :
37+
foundJob = True
38+
if not foundJob :
39+
print("faild to query jobs")
40+
else :
41+
print("found job number : {}".format(jobInfoPtr.jobInfoHead.numJobs))
42+
if jobInfoPtr.jobInfoHead.numJobs > 0 :
43+
job = lsf.jobInfoEnt()
44+
job = lsf.lsb_fetchjobinfo(more, jobQuery.nCols, jobQuery.colIndexs, jobQuery.query)
45+
if job == None:
46+
print("no job found")
47+
while job != None:
48+
print("job <{}> from user ({}) status is {}".format(lsf.lsb_jobid2str(job.jobId),job.user, job.status))
49+
job = lsf.lsb_fetchjobinfo(more, jobQuery.nCols, jobQuery.colIndexs, jobQuery.query)
50+
51+
52+
if __name__ == "__main__":
53+
joblist = []
54+
if len(sys.argv) < 2:
55+
joblist = ['0']
56+
else:
57+
for jobid in sys.argv[1:]:
58+
joblist.append(jobid)
59+
joblist = ['3530','3531']
60+
get_job_info(joblist)

pythonlsf/lsf.i

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,20 @@ PyObject * get_pids_from_stream(struct jRusage * jrusage) {
715715
return result;
716716
}
717717

718+
long * buildQueryColIndexs() {
719+
long * colIndexs = NULL;
720+
int i = 0;
721+
722+
colIndexs = calloc(113, sizeof(long));
723+
for (i= 0; i < 113; i++) {
724+
colIndexs[i] = i;
725+
}
726+
colIndexs[1] = 2;
727+
colIndexs[2] = 1;
728+
colIndexs[9] = 10;
729+
return colIndexs;
730+
}
731+
718732
PyObject * get_host_info_all() {
719733
struct hostInfoEnt *hostinfo;
720734
char **hosts = NULL;

0 commit comments

Comments
 (0)