Signal handler for non-fatal signals which raises or logs an error and exits with failure.
971136
def _handle_signal_gracefully(cls, signum, signame, traceback_lines):
    """"""
    # Extract the stack, and format an entry to be written to the exception log.
    formatted_traceback = cls._format_traceback(traceback_lines=traceback_lines,
                                                should_print_backtrace=True)
    signal_error_log_entry = cls._CATCHABLE_SIGNAL_ERROR_LOG_FORMAT.format(
      signum=signum,
      signame=signame,
      formatted_traceback=formatted_traceback)
    # TODO: determine the appropriate signal-safe behavior here (to avoid writing to our file
    # descriptors re-entrantly, which raises an IOError).
    # This method catches any exceptions raised within it.
    cls.log_exception(signal_error_log_entry)

    # Create a potentially-abbreviated traceback for the terminal or other interactive stream.
    formatted_traceback_for_terminal = cls._format_traceback(
      traceback_lines=traceback_lines,
      should_print_backtrace=cls._should_print_backtrace_to_terminal)
    terminal_log_entry = cls._CATCHABLE_SIGNAL_ERROR_LOG_FORMAT.format(
      signum=signum,
      signame=signame,
      formatted_traceback=formatted_traceback_for_terminal)
    # Exit, printing the output to the terminal.
    cls._exit_with_failure(terminal_log_entry)
1313909
def signal_handler(signum, frame):
    
    # signals are CONSTANTS so there is no mapping from signum to description
    # so please add to the mapping in case you use more signals!
    description = '%d' % signum
    if signum == 2:
        description = 'SIGINT'
    elif signum == 15:
        description = 'SIGTERM'
    raise GracefulExit(description)
1018639
def _signal(self, sig, pid=None):
        
        log = self._params.get('log', self._discard)
        if pid is None:
            pids = self.get_pids()
        else:
            pids = [pid]
        for pid in pids:
            try:
                os.kill(pid, sig)
                log.debug("Signalled '%s' pid %d with %s", self._name, pid, utils.signame(sig))
            except Exception as e:
                log.warning("Failed to signal '%s' pid %d with %s -- %s", self._name, pid, utils.signame(sig), e)
1215059
function handler ( err, data ){
      if ( callback != null ){
        callback.apply( b9, arguments );
      }
      // only emit events when there is no error
      if ( err == null ){
        b9.emit.call( b9, method, data );
      }
    }
37060
def error_msg_callback(self, callback):
        """"""
        if callable(callback):
            self._error_msg_callback = callback
        else:
            self._error_msg_callback = None
1170953
def _method_error_handler(self, response: Dict[str, Any]):
        
        exp = response.get('MESSAGE')
        code = response.get("CODE")
        ID = exp.get("ID")
        raise abort(code, ID=ID, message=exp.get('MESSAGE'))
40513
function abortSignal(signal) {
    if (abortedFlags.get(signal) !== false) {
        return;
    }
    abortedFlags.set(signal, true);
    signal.dispatchEvent({ type: "abort" });
}
361172
def handle_signal(self, sig, frame):
        """"""
        if sig in [signal.SIGINT]:
            log.warning("Ctrl-C pressed, shutting down...")
        if sig in [signal.SIGTERM]:
            log.warning("SIGTERM received, shutting down...")
        self.cleanup()
        sys.exit(-sig)
967896
def setup_signal_handlers(self):
        ''''''
        if platform.system() == 'Windows':
            _logger.warning(_(
                'Graceful stopping with Unix signals is not supported '
                'on this OS.'
            ))
            return

        event_loop = asyncio.get_event_loop()
        graceful_called = False

        def graceful_stop_callback():
            nonlocal graceful_called

            if graceful_called:
                forceful_stop_callback()
                return

            graceful_called = True

            _logger.info(_('Stopping once all requests complete...'))
            _logger.info(_('Interrupt again to force stopping immediately.'))
            self.stop()

        def forceful_stop_callback():
            _logger.info(_('Forcing immediate stop...'))
            logging.raiseExceptions = False
            event_loop.stop()

        event_loop.add_signal_handler(signal.SIGINT, graceful_stop_callback)
        event_loop.add_signal_handler(signal.SIGTERM, forceful_stop_callback)
699915
def __error_callback(self, exception, interval):
        
        logging.error('Error while publishing {}'.format(
            exception))
        logging.info('Retry in %s seconds.', interval)
670145
def _handle_sigint(self, signum: int, frame: Any) -> None:
        """"""
        logger.warning("Catched SIGINT")
        self.shutdown()
812093
def on_timeout(limit, handler=handler_func, hint=None):
    
    def notify_handler(signum, frame):
        handler("'%s' is not finished in %d second(s)." % (hint, limit))

    def __decorator(function):
        def __wrapper(*args, **kwargs):
            import signal
            signal.signal(signal.SIGALRM, notify_handler)
            signal.alarm(limit)
            result = function(*args, **kwargs)
            signal.alarm(0)
            return result
        return wraps(function)(__wrapper)
    return __decorator
644305
def _trapped_signals(self, client):
    """"""
    signal_handler = PailgunClientSignalHandler(
      client,
      timeout=self._bootstrap_options.for_global_scope().pantsd_pailgun_quit_timeout)
    with ExceptionSink.trapped_signals(signal_handler):
      yield
1206580
def handle_errors
      trap('HUP')  { }
      trap('TERM') { close_log; Process.exit! }
      trap('KILL') { close_log; Process.exit! }
      trap('INT')  { close_log; Process.exit! }
    end
60834
function signalHandler(signal)
{
    var exit = true;
    cleanupHandlers.forEach(function (cleanup) {
        if (cleanup(null, signal) === false)
            exit = false;
    });
    if (exit) {
        if (signal === 'SIGINT' && messages && messages.ctrl_C !== '')
            process.stderr.write(messages.ctrl_C + "\n");
        uninstall(); // don't cleanup again
        // necessary to communicate the signal to the parent process
        process.kill(process.pid, signal);
    }
}
1101321
def _log_unhandled_exception_and_exit(cls, exc_class=None, exc=None, tb=None, add_newline=False):
    """"""
    exc_class = exc_class or sys.exc_info()[0]
    exc = exc or sys.exc_info()[1]
    tb = tb or sys.exc_info()[2]

    # This exception was raised by a signal handler with the intent to exit the program.
    if exc_class == SignalHandler.SignalHandledNonLocalExit:
      return cls._handle_signal_gracefully(exc.signum, exc.signame, exc.traceback_lines)

    extra_err_msg = None
    try:
      # Always output the unhandled exception details into a log file, including the traceback.
      exception_log_entry = cls._format_unhandled_exception_log(exc, tb, add_newline,
                                                                should_print_backtrace=True)
      cls.log_exception(exception_log_entry)
    except Exception as e:
      extra_err_msg = 'Additional error logging unhandled exception {}: {}'.format(exc, e)
      logger.error(extra_err_msg)

    # Generate an unhandled exception report fit to be printed to the terminal (respecting the
    # Exiter's should_print_backtrace field).
    stderr_printed_error = cls._format_unhandled_exception_log(
      exc, tb, add_newline,
      should_print_backtrace=cls._should_print_backtrace_to_terminal)
    if extra_err_msg:
      stderr_printed_error = '{}\n{}'.format(stderr_printed_error, extra_err_msg)
    cls._exit_with_failure(stderr_printed_error)
1022313
def process_exception(self, request, exception):
        
        if hasattr(threadlocal, 'auditlog'):
            pre_save.disconnect(sender=LogEntry, dispatch_uid=threadlocal.auditlog['signal_duid'])

        return None