Example Hook not working

I tried to describe the Hook when a queue is not specified in the qsub.
I referred to the sample on p. 264 of the PBS Professional 2022.1 Hooks Guide, but it does not work properly.

If I specify a queue, it works properly.

The created HOOK is as follows

import pbs
e = pbs.event()

if e.job.queue == None:
  target_qname = pbs.server().default_queue
else:
  target_qname = e.job.queue.name

if e.job.interactive:
  e.job.Resource_List['walltime'] = pbs.duration('48:00:00')

if target_qname == "workq":
  e.job.Resource_List['walltime'] = pbs.duration('00:30:00')

e.accept()

The error at runtime is as follows

11/10/2022 15:44:44;0001;Server@centos73-hh;Svr;Server@centos73-hh;PBS server internal error (15011) in Error evaluating Python script, <type 'exceptions.AttributeError'>
11/10/2022 15:44:44;0001;Server@centos73-hh;Svr;Server@centos73-hh;PBS server internal error (15011) in Error evaluating Python script, 'str' object has no attribute 'name'
11/10/2022 15:44:44;0100;Server@centos73-hh;Hook;walltime;queuejob hook 'walltime' encountered an exception, request rejected

The example in the manual does not work properly.

Any advice would be appreciated!

Please try this:

import pbs
e = pbs.event()
j = e.job
def getseconds(time_str):
    hour, minute, second = time_str.split(':')
    return int(hour) * 3600 + int(minute) * 60 + int(second)
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)

target_qname=j.queue.name

if e.job.interactive:
    j.Resource_List["walltime"] = pbs.duration(getseconds("00:48:00"))
if target_qname == "workq":
    j.Resource_List["walltime"] = pbs.duration(getseconds("00:30:00"))

e.accept()

Adarsh-san,

Thank you for your reply.
Hook worked properly.

Thanks a lot.

1 Like