def _HandleControlC(signal_num, cur_stack_frame): """Called when user hits ^C. This function prints a brief message instead of the normal Python stack trace (unless -D option is used). Args: signal_num: Signal that was caught. cur_stack_frame: Unused. """ if debug_level >= 2: stack_trace = ''.join(traceback.format_list(traceback.extract_stack())) _OutputAndExit('DEBUG: Caught CTRL-C (signal %d) - Exception stack trace:\n' ' %s' % (signal_num, re.sub('\\n', '\n ', stack_trace)), exception=ControlCException()) else: _OutputAndExit('Caught CTRL-C (signal %d) - exiting' % signal_num, exception=ControlCException())
def MultithreadedMainSignalHandler(signal_num, cur_stack_frame): """Final signal handler for multi-threaded main process.""" if signal_num == signal.SIGINT: if logging.getLogger().isEnabledFor(logging.DEBUG): stack_trace = ''.join(traceback.format_list(traceback.extract_stack())) err = ('DEBUG: Caught CTRL-C (signal %d) - Exception stack trace:\n' ' %s' % (signal_num, re.sub('\\n', '\n ', stack_trace))) try: sys.stderr.write(err.encode(UTF8)) except UnicodeDecodeError: # Can happen when outputting invalid Unicode filenames. sys.stderr.write(err) else: sys.stderr.write('Caught CTRL-C (signal %d) - exiting\n' % signal_num) metrics.LogFatalError(exception=ControlCException()) metrics.Shutdown() KillProcess(os.getpid())