@@ -178,9 +178,21 @@ def _update_nodelist(self, job, nodespec):
178178 job ._nodelist = [x .split ('/' )[0 ] for x in nodespec .split ('+' )]
179179 job ._nodelist .sort ()
180180
181- # The second argument is to specialise some code paths to PBS Pro only, but
182- # not Torque.
183- def _poll (self , is_pbs_pro , * jobs ):
181+ def _query_exit_code (self , job ):
182+ '''Try to retrieve the exit code of a past job.'''
183+
184+ # With PBS Pro we can obtain the exit status of a past job
185+ extended_info = osext .run_command (f'qstat -xf { job .jobid } ' )
186+ exit_status_match = re .search (
187+ r'^ *Exit_status *= *(?P<exit_status>\d+)' , extended_info .stdout ,
188+ flags = re .MULTILINE ,
189+ )
190+ if exit_status_match :
191+ return int (exit_status_match .group ('exit_status' ))
192+
193+ return None
194+
195+ def poll (self , * jobs ):
184196 def output_ready (job ):
185197 # We report a job as finished only when its stdout/stderr are
186198 # written back to the working directory
@@ -211,19 +223,7 @@ def output_ready(job):
211223 if job .cancelled or output_ready (job ):
212224 self .log (f'Assuming job { job .jobid } completed' )
213225 job ._completed = True
214- if is_pbs_pro :
215- # With PBS Pro we can obtain the exit status of the job,
216- # in case it actually failed.
217- extended_info = osext .run_command (
218- f'qstat -xf { job .jobid } '
219- )
220- exit_status_match = re .search (
221- r'^ *Exit_status *= *(?P<exit_status>\d+)' ,
222- extended_info .stdout ,
223- flags = re .MULTILINE ,
224- )
225- if exit_status_match :
226- job ._exitcode = int (exit_status_match .group ('exit_status' ))
226+ job ._exitcode = self ._query_exit_code (job )
227227
228228 return
229229
@@ -292,13 +292,13 @@ def output_ready(job):
292292 job ._exception = JobError ('maximum pending time exceeded' ,
293293 job .jobid )
294294
295- def poll (self , * job ):
296- self ._poll (True , * job )
297-
298295
299296@register_scheduler ('torque' )
300297class TorqueJobScheduler (PbsJobScheduler ):
301298 TASKS_OPT = '-l nodes={num_nodes}:ppn={num_cpus_per_node}'
302299
303- def poll (self , * job ):
304- self ._poll (False , * job )
300+ def _query_exit_code (self , job ):
301+ '''Try to retrieve the exit code of a past job.'''
302+
303+ # Torque does not provide a way to retrieve the history of jobs
304+ return None
0 commit comments