Suppose my running jobs are as given below
#qstat -aw
ip-10-77-173-99:
Req’d Req’d Elap
Job ID Username Queue Jobname SessID NDS TSK Memory Time S Time
222.ip-10-77-173-99 sahuhem dcv Custom_DCV_Sess 7644 1 1 – 70:00 R 05:43
I want to get the job Quename using python pbs library. How can i do that
I tried below but it gives error.
pbs.server().job(‘222’).queue()
Traceback (most recent call last):
File “”, line 1, in
File “/opt/pbs/lib/python/altair/pbs/v1/_svr_types.py”, line 710, in job
return pbs_statobj(“job”, jobid, self._connect_server)
File “/opt/pbs/lib/python/altair/pbs/v1/_svr_types.py”, line 234, in pbs_statobj
vo = getattr(pr, r)
AttributeError: ‘pbs_resource’ object has no attribute ‘myhpc_cunit’
a quick clarification : using hooks or you want to get it programaticaly using python + pbs libraries (to create client command of your own).
Mainly I want to get it programaticaly using python + pbs libraries.
Also appreciate if you can provide a hook script.
You can print the queuename in the $PBS_HOME/server_logs/YYYYMMDD using this queuejob event hook
import pbs
e = pbs.event()
j = e.job
if ( hasattr(j.queue, "name")) :
pbs.logmsg(pbs.LOG_ERROR, "queue has name %s" % j.queue.name)
else :
j.queue = pbs.server().queue(str(pbs.server().default_queue))
pbs.logmsg(pbs.LOG_ERROR, "queue has name %s" % j.queue.name)
You can use the PBS IFL library and write a c program to interace witht he PBS Server to get the queue name :
Ref: https://help.altair.com/2024.1.0/PBS%20Professional/PBSProgramGuide2024.1.pdf
Sample code:jobqueuename.c
#include <stdio.h>
#include <stdlib.h>
#include <pbs_ifl.h>
int main(int argc, char *argv[]) {
int connect;
struct batch_status *job_status;
struct attrl *attr;
if (argc != 2) {
fprintf(stderr, "Usage: %s <job_id>\n", argv[0]);
return 1;
}
// Connect to PBS server
connect = pbs_connect(NULL); // NULL = default server
if (connect < 0) {
perror("pbs_connect");
return 1;
}
// Get full status of the job
job_status = pbs_statjob(connect, argv[1], NULL, NULL);
if (!job_status) {
perror("pbs_statjob");
pbs_disconnect(connect);
return 1;
}
// Search for 'queue' attribute
for (attr = job_status->attribs; attr; attr = attr->next) {
if (strcmp(attr->name, ATTR_queue) == 0) {
printf("Job %s is in queue: %s\n", argv[1], attr->value);
break;
}
}
// Clean up
pbs_statfree(job_status);
pbs_disconnect(connect);
return 0;
}
source /etc/pbs.conf
locate libpbs.so.0
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/pbs/lib
gcc -o jobqueuename jobqueuename.c -I/opt/pbs/include -L/opt/pbs/lib -lpbs
./jobqueuename
Usage: ./jobqueuename <job_id of the running job>
./jobqueuename 145
Job 145 is in queue: workq
You can extend the code to your requirements and following the progamming guide.
1 Like
is there any equivalent python script as that of “jobqueuename.c” ?
Hi Hemanta
For an example of writing Python code to get PBS info see my script here:
‘GitHub - UTS-eResearch/pbsweb: Web interface to show nodes, queues and jobs on a High Performance Compute Cluster using PBS Pro ’
There are some simple examples under the tests directory. The only tricky bit is getting the pbs object file created to import into your Python code.
Mike
1 Like
Since that request, I have come up with a simpler way to access PBS IFL routines from python. See the github project:
Python versions of PBS qstat, pbs_rstat, and pbsfs
Of interest is the build_pbs_ifl script that builds _pbs_ifl.so and pbs_ifl.py.
Example use to show queue of job:
$ cat tt.py
#!/usr/bin/env python3
import pbs_ifl as ifl
c = ifl.pbs_connect('')
bs = ifl.pbs_statjob(c, None, None, None)
for job in bs:
print(job['id'], job['queue'])
ifl.pbs_disconnect(c)
$ ./tt.py
3000.rhserver workq
2 Likes
Thanks for the update. However, I found below error
[root@e22c7dfa2a97607 sahuhem]# /usr/bin/env python3
Python 3.9.20 (main, Sep 26 2024, 20:59:47)
[GCC 8.5.0 20210514 (Red Hat 8.5.0-22)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
import sys
import os
sys.path.append(f’/opt/pbs/lib/python/‘)
sys.path.append(f’/opt/pbs/lib/python/altair’)
import pbs
import pbs_ifl as ifl
c = ifl.pbs_connect(‘’)
bs = ifl.pbs_statjob(c, None, None, None)
print (bs)
<pbs_ifl.batch_status; proxy of <Swig Object of type ‘batch_status *’ at 0x7ff60f6a6fc0> >
That’s not an error. It just means that python has no method to display a “batch_status” object, so it just tells you its address.
If you want to see what’s in bs, convert it to a list:
print(list(bs))