Try to gracefully disconnect from each network, unload all scripts and
 exit properly.

 @param [optional, Symbol] signal The signal received by the system, if any.
429812
def quit signal = :SIGINT
      @networks.each do |network|
        network.transmit :QUIT, 'Got SIGINT?'
        network.disconnect
      end

      EventMachine.stop
    end
725243
def remove_signals_listeners(instance):
    
    if hasattr(instance, "__listeners__"):
        for listener in list(instance.__listeners__):
            for signal in instance.__listeners__[listener]:
                signal.disconnect(listener)
1328054
def disconnect_all(self):
        
        if not self.__connected:
            return  # assert self.__connected, "disconnect_all() already in \"disconnected\" state"
        self.__disconnecting = True
        try:
            for signal in self.__signals:
                signal.disconnect(self.__signalReceived)
            if self.__slot is not None:
                self.__sigDelayed.disconnect(self.__slot)
            self.__connected = False
        finally:
            self.__disconnecting = False
590716
def kill(signal)
      Process.kill(signal.to_s, pid) if pid && @self_started
      @killed = true
    rescue Errno::ESRCH => e
      log "Can't kill #{pid}: #{e}"
    end
1142622
public function handler($signal) {
        switch ($signal) {
            case SIGALRM :
                $this->isStopped = true;
                $this->closeChildren();
                break;
            case SIGINT :
            case SIGKILL :
                $this->broadcast($signal);
                exit;
            default: break;
        }
    }
581968
def disconnect_all(self, message=""):
        """"""
        with self.mutex:
            for conn in self.connections:
                conn.disconnect(message)
78027
def _handle_terminate(self, signal_number, _):
        """"""
        signal_names = {
            signal.SIGINT: 'SIGINT',
            signal.SIGQUIT: 'SIGQUIT',
            signal.SIGTERM: 'SIGTERM',
        }
        message = 'Terminated by {name} ({number})'.format(
            name=signal_names[signal_number], number=signal_number)
        self._shutdown(message, code=128+signal_number)
841295
def signal_handler(sig, frame):
    
    for client in connected_clients[:]:
        if client.is_asyncio_based():
            client.start_background_task(client.disconnect, abort=True)
        else:
            client.disconnect(abort=True)
    return original_signal_handler(sig, frame)
655337
def handle_end_signal(self):
        
        try:
            signal.signal(signal.SIGTERM, self.catch_end_signal)
            signal.signal(signal.SIGINT, self.catch_end_signal)
        except ValueError:
            self.log('Signals cannot be caught in a Thread', level='warning')
845822
def trap_signals
      shutdown = proc do |signal|
        STDERR.puts "\nReceived #{signal}, shutting down..."
        stop
        join
        exit 1
      end
      trap('INT')  { shutdown.call 'SIGINT'  }
      trap('TERM') { shutdown.call 'SIGTERM' }
    end
843995
function serverClose (signal, done) {
  _logger.info('Process received ' + signal + ', exiting ....')
  if (done === undefined) {
    done = function () {
      process.exit(0)
    }
  }
  if (server) {
    server.close(done)
  } else {
    done()
  }
}
999696
def clean_exit(signum, frame=None):
    
    global exiting
    if exiting:
        # Since this is set up as a handler for SIGCHLD when this kills one
        # child it gets another signal, the global exiting avoids this running
        # multiple times.
        LOG.debug('Exit in progress clean_exit received additional signal %s' % signum)
        return

    LOG.info('Received signal %s, beginning graceful shutdown.' % signum)
    exiting = True
    wait_for_exit = False

    for process in processors:
        try:
            if process.is_alive():
                # Sends sigterm which any processes after a notification is sent attempt to handle
                process.terminate()
                wait_for_exit = True
        except Exception:  # nosec
            # There is really nothing to do if the kill fails, so just go on.
            # The # nosec keeps bandit from reporting this as a security issue
            pass

    # wait for a couple seconds to give the subprocesses a chance to shut down correctly.
    if wait_for_exit:
        time.sleep(2)

    # Kill everything, that didn't already die
    for child in multiprocessing.active_children():
        LOG.debug('Killing pid %s' % child.pid)
        try:
            os.kill(child.pid, signal.SIGKILL)
        except Exception:  # nosec
            # There is really nothing to do if the kill fails, so just go on.
            # The # nosec keeps bandit from reporting this as a security issue
            pass

    if signum == signal.SIGTERM:
        sys.exit(0)

    sys.exit(signum)
1233410
protected function disconnect()
    {
        $this->log('closing sockets ... ', Net_Notifier_Logger::VERBOSITY_ALL);

        foreach ($this->clients as $client) {
            $client->startClose(
                Net_Notifier_WebSocket_Connection::CLOSE_GOING_AWAY,
                'Server shutting down.'
            );
        }

        $this->clients = array();
        $this->socket  = null;

        $this->log('done' . PHP_EOL, Net_Notifier_Logger::VERBOSITY_ALL, false);

        $this->connected = false;
    }
318652
def _exitOnSignal(sigName, message):
    
    import signal

    try:
        sigNumber = getattr(signal, sigName)
    except AttributeError:
        # the signal constants defined in the signal module are defined by
        # whether the C library supports them or not. So, SIGPIPE might not
        # even be defined.
        return

    def handler(sig, f):
        sys.exit(message)

    try:
        signal.signal(sigNumber, handler)
    except ValueError:
        # It's also possible the signal is defined, but then it's invalid. In
        # this case, signal.signal raises ValueError.
        pass
268321
def signals(self, signals=('QUIT', 'USR1', 'USR2')):
        ''''''
        for sig in signals:
            signal.signal(getattr(signal, 'SIG' + sig), self.handler)
649774
def _signal_handler(self, *_) -> None:
        
        if self._num_signals == 0:
            logging.warning('Interrupt signal caught - training will be terminated')
            logging.warning('Another interrupt signal will terminate the program immediately')
            self._num_signals += 1
        else:
            logging.error('Another interrupt signal caught - terminating program immediately')
            sys.exit(2)
1341433
def signal_handler(signal_name, frame):
    """"""
    sys.stdout.flush()
    print("\nSIGINT in frame signal received. Quitting...")
    sys.stdout.flush()
    sys.exit(0)