code: def signal_catcher(callback):
      
      def _catch_exit_signal(sig_num, _frame):
          print('Received signal {:d} invoking callback...'.format(sig_num))
          callback()
  
      signal.signal(signal.SIGINT, _catch_exit_signal)
      signal.signal(signal.SIGQUIT, _catch_exit_signal)
      signal.signal(signal.SIGTERM, _catch_exit_signal)
      yield
docs: Catch signals and invoke the callback method