From 7090b625df3027e9889e20ed554d1b7b6ec484cf Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Mon, 11 Aug 2014 09:47:00 -0300 Subject: [PATCH] avocado.job: Properly handle Ctrl+C inside avocado Handle KeyboardInterrupt inside avocado, making Ctrl+C to terminate the program, instead of generating a python backtrace. Signed-off-by: Lucas Meneghel Rodrigues --- avocado/job.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/avocado/job.py b/avocado/job.py index eee1be37..140ab846 100644 --- a/avocado/job.py +++ b/avocado/job.py @@ -126,10 +126,15 @@ class TestRunner(object): e_msg = "Timeout reached waiting for %s to end" % instance raise exceptions.TestTimeoutError(e_msg) + def interrupt_handler(signum, frame): + e_msg = "Test %s interrupted by user" % instance + raise exceptions.TestInterruptedError(e_msg) + instance = self.load_test(params) queue.put(instance.get_state()) signal.signal(signal.SIGUSR1, timeout_handler) + signal.signal(signal.SIGINT, interrupt_handler) self.result.start_test(instance.get_state()) try: @@ -431,6 +436,12 @@ class Job(object): except exceptions.OptionValidationError, details: self.output_manager.log_fail_header(str(details)) return error_codes.numeric_status['AVOCADO_JOB_FAIL'] + except KeyboardInterrupt: + for child in multiprocessing.active_children(): + os.kill(child.pid, signal.SIGINT) + self.output_manager.log_header('\n') + self.output_manager.log_header('Interrupted by user request') + sys.exit(error_codes.numeric_status['AVOCADO_JOB_FAIL']) except Exception, details: self.status = "ERROR" -- GitLab