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: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 e2623731
......@@ -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"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册