Need support on implementing a hook

Objective: Need to implement a hook to check group_list parameter

Below is the Hook that I have tried to create

import pbs
import sys

try:
if pbs.event().queue.name == “workq” and not pbs.event().job.group_list:
pbs.event().reject(“Job has been rejected as group list is not defined”)

except SystemExit:
pass

except:
pbs.event().reject(“Job rejected as group list has not been defined”)

Below is the job which runs a very simple python code and has group list parameter
Capture

So as an output in both positive and negative case it displays the message from the except block. I have tried various ways for group_list check but nothing is working out.

Expectation: If group list parameter is empty job should not execute and return error message which is present in expect in case if its present the job should get executed successfully

qmgr -c ‘create hook Grouplist event=“queuejob”’
qmgr -c ‘import hook Grouplist application/x-python default Group_List_Hook.py’

Please try this python script:

 import pbs
import sys

e = pbs.event()
j = e.job

if ( hasattr(j.queue, "name")):
    pbs.logmsg(pbs.LOG_DEBUG, "queue has name %s" % j.queue.name)
else:
    j.queue = pbs.server().queue(str(pbs.server().default_queue))
    pbs.logmsg(pbs.LOG_DEBUG, "queue has name %s" % j.queue.name)
pbs.logmsg(pbs.LOG_DEBUG, "  Group list is %s." % (j.group_list))
if (j.group_list)==None:
    e.reject(' The job does not request a group list. \nExample: qsub -q workq -W group_list=pbsdata@hostname\nTry \"man qsub\" for more information')