| 11 | |
| 12 | |
| 13 | class SignalProc(base.TestProcObserver): |
| 14 | def __init__(self): |
| 15 | super(SignalProc, self).__init__() |
| 16 | self.exit_code = utils.EXIT_CODE_PASS |
| 17 | signal.signal(signal.SIGINT, self._on_ctrlc) |
| 18 | signal.signal(signal.SIGTERM, self._on_sigterm) |
| 19 | |
| 20 | def _on_ctrlc(self, _signum, _stack_frame): |
| 21 | logging.warning('Ctrl-C detected, early abort...') |
| 22 | self.exit_code = utils.EXIT_CODE_INTERRUPTED |
| 23 | self.stop() |
| 24 | if logging.getLogger().isEnabledFor(logging.INFO): |
| 25 | faulthandler.dump_traceback() |
| 26 | |
| 27 | def _on_sigterm(self, _signum, _stack_frame): |
| 28 | logging.warning('SIGTERM received, early abort...') |
| 29 | self.exit_code = utils.EXIT_CODE_TERMINATED |
| 30 | self.stop() |
| 31 | if logging.getLogger().isEnabledFor(logging.INFO): |
| 32 | faulthandler.dump_traceback() |
| 33 | |
| 34 | def worst_exit_code(self, results): |
| 35 | exit_code = results.exit_code() |
| 36 | # Indicate if a SIGINT or SIGTERM happened. |
| 37 | return max(exit_code, self.exit_code) |