def handle_interrupt_forcefully(self, signum: int,
                                    _frame: types.FrameType) -> None:
        """Second handler for interrupt signals to exit forcefully.

        Args:
            signum: Signal number of the interrupt signal retrieved.
        """
        _logger.debug("Interrupt handler called a second time with %d", signum)
        log.fatal(
            "Forceful kill signal retrieved... Hello darkness my old friend")
        sys.exit(customtypes.Exit.signal + signum)
예제 #2
0
    def handle_exception(
        self,
        initial_handler: ExceptionHandler,
        exc_type: Type[BaseException],
        exc_value: BaseException,
        traceback: types.TracebackType,
    ) -> None:
        """Custom exception handler for uncaught exceptions.

        In addition to the standard python exception handler a log message is called and
        the application tries to exit gracefully.
        """
        log.error("Uncaught exception! Exiting gracefully and printing stack...")
        initial_handler(exc_type, exc_value, traceback)
        try:
            self._app.exit(customtypes.Exit.err_exception)
        # We exit immediately by killing the application if an error in the graceful
        # exit occurs
        except Exception as e:  # pylint: disable=broad-except
            log.fatal("Uncaught exception in graceful exit... Committing suicide :(")
            log.fatal("Exception: %r", e)
            sys.exit(customtypes.Exit.err_suicide)