1 # Copyright 2018 the V8 project authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 import signal 6 7 from . import base 8 from testrunner.local import utils 9 10 11 class SignalProc(base.TestProcObserver): 12 def __init__(self): 13 super(SignalProc, self).__init__() 14 self.exit_code = utils.EXIT_CODE_PASS 15 16 def setup(self, *args, **kwargs): 17 super(SignalProc, self).setup(*args, **kwargs) 18 # It should be called after processors are chained together to not loose 19 # catched signal. 20 signal.signal(signal.SIGINT, self._on_ctrlc) 21 signal.signal(signal.SIGTERM, self._on_sigterm) 22 23 def _on_ctrlc(self, _signum, _stack_frame): 24 print '>>> Ctrl-C detected, early abort...' 25 self.exit_code = utils.EXIT_CODE_INTERRUPTED 26 self.stop() 27 28 def _on_sigterm(self, _signum, _stack_frame): 29 print '>>> SIGTERM received, early abort...' 30 self.exit_code = utils.EXIT_CODE_TERMINATED 31 self.stop() 32