mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-10-30 22:54:18 +00:00 
			
		
		
		
	fw/execution: fix Exception on abort
Hitting CTRL-C will abort execution of the current job, but will still trigger run finalization, and possibly, post-processing and teardown of the current job. If an exception is raised during this post-process/teardown, the previous exception state (for the KeybardInterrupt) will be clobbered. That means that, after the new exception has been handled, WA would attempt to execute the next job, rather than go to finalization of the run. To avoid this, set a flag in the context upon catching KeybardInterrupt, and check this flag before attempting to execute the next job in the queue.
This commit is contained in:
		
				
					committed by
					
						 Marc Bonnici
						Marc Bonnici
					
				
			
			
				
	
			
			
			
						parent
						
							fda418093d
						
					
				
				
					commit
					9689420cff
				
			| @@ -98,6 +98,7 @@ class ExecutionContext(object): | |||||||
|         self.current_job = None |         self.current_job = None | ||||||
|         self.successful_jobs = 0 |         self.successful_jobs = 0 | ||||||
|         self.failed_jobs = 0 |         self.failed_jobs = 0 | ||||||
|  |         self.run_interrupted = False | ||||||
|  |  | ||||||
|     def start_run(self): |     def start_run(self): | ||||||
|         self.output.info.start_time = datetime.utcnow() |         self.output.info.start_time = datetime.utcnow() | ||||||
| @@ -372,6 +373,8 @@ class Runner(object): | |||||||
|             self.send(signal.RUN_INITIALIZED) |             self.send(signal.RUN_INITIALIZED) | ||||||
|  |  | ||||||
|             while self.context.job_queue: |             while self.context.job_queue: | ||||||
|  |                 if self.context.run_interrupted: | ||||||
|  |                     raise KeyboardInterrupt() | ||||||
|                 with signal.wrap('JOB_EXECUTION', self, self.context): |                 with signal.wrap('JOB_EXECUTION', self, self.context): | ||||||
|                     self.run_next_job(self.context) |                     self.run_next_job(self.context) | ||||||
|  |  | ||||||
| @@ -425,6 +428,7 @@ class Runner(object): | |||||||
|         except (Exception, KeyboardInterrupt) as e: # pylint: disable=broad-except |         except (Exception, KeyboardInterrupt) as e: # pylint: disable=broad-except | ||||||
|             log.log_error(e, self.logger) |             log.log_error(e, self.logger) | ||||||
|             if isinstance(e, KeyboardInterrupt): |             if isinstance(e, KeyboardInterrupt): | ||||||
|  |                 context.run_interrupted = True | ||||||
|                 job.set_status(Status.ABORTED) |                 job.set_status(Status.ABORTED) | ||||||
|                 raise e |                 raise e | ||||||
|             else: |             else: | ||||||
| @@ -467,6 +471,7 @@ class Runner(object): | |||||||
|                 with signal.wrap('JOB_EXECUTION', self, context): |                 with signal.wrap('JOB_EXECUTION', self, context): | ||||||
|                     job.run(context) |                     job.run(context) | ||||||
|             except KeyboardInterrupt: |             except KeyboardInterrupt: | ||||||
|  |                 context.run_interrupted = True | ||||||
|                 job.set_status(Status.ABORTED) |                 job.set_status(Status.ABORTED) | ||||||
|                 raise |                 raise | ||||||
|             except Exception as e: |             except Exception as e: | ||||||
| @@ -488,6 +493,7 @@ class Runner(object): | |||||||
|                     raise |                     raise | ||||||
|  |  | ||||||
|         except KeyboardInterrupt: |         except KeyboardInterrupt: | ||||||
|  |             context.run_interrupted = True | ||||||
|             job.set_status(Status.ABORTED) |             job.set_status(Status.ABORTED) | ||||||
|             raise |             raise | ||||||
|         finally: |         finally: | ||||||
| @@ -512,7 +518,10 @@ class Runner(object): | |||||||
|                 self.context.failed_jobs += 1 |                 self.context.failed_jobs += 1 | ||||||
|         else:  # status not in retry_on_status |         else:  # status not in retry_on_status | ||||||
|             self.logger.info('Job completed with status {}'.format(job.status)) |             self.logger.info('Job completed with status {}'.format(job.status)) | ||||||
|             self.context.successful_jobs += 1 |             if job.status != 'ABORTED': | ||||||
|  |                 self.context.successful_jobs += 1 | ||||||
|  |             else: | ||||||
|  |                 self.context.failed_jobs += 1 | ||||||
|  |  | ||||||
|     def retry_job(self, job): |     def retry_job(self, job): | ||||||
|         retry_job = Job(job.spec, job.iteration, self.context) |         retry_job = Job(job.spec, job.iteration, self.context) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user