Reimplementation of stopConsumer to allow non-amqp consumer to react gracefully to stop signals
@param int $sigNo
552526
public function haltConsumer($sigNo)
    {
        if ($this->consumer instanceof BaseConsumer) {
            // Process current message, then halt consumer
            $this->consumer->forceStopConsumer();

            // Halt consumer if waiting for a new message from the queue
            try {
                $this->consumer->stopConsuming();
            } catch (AMQPTimeoutException $e) {
                // exit gracefully with a message
                echo("Stopped because: Received stop signal $sigNo\n");
            }

        } elseif ($this->consumer instanceof \Kaliop\QueueingBundle\Queue\SignalHandlingConsumerInterface) {

            $this->consumer->forceStop("Received stop signal $sigNo");

        } else {
            exit();
        }
    }
1179393
protected function shutdown($signo = false)
    {
        $this->shutdown = true;
        $this->waitAll(true);
        Daemon::$shm_wstate->delete();
        file_put_contents(Daemon::$config->pidfile->value, '');
        posix_kill(getmypid(), SIGKILL);
        exit(0);
    }
47741
def handler(self, signum, frame):  # pragma: no cover
        ''''''
        if signum in (signal.SIGTERM, signal.SIGINT, signal.SIGQUIT):
            self.stop(signum)
            os._exit(0)
1319233
public static function handler($iSignal) {

		if (self::$bExit) {
			return;
		}

		switch($iSignal) {
			case SIGTERM:
			case SIGKILL:
			case SIGINT:
				self::$bExit = TRUE;
				break;
			default:
				break;
		}
	}
1094256
public void resumeConsumer(int suspendFlag)
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "resumeConsumer", this);
    
    ArrayList<AORequestedTick> satisfiedTicks = null;

    synchronized(parent) // AOStream
    {
      try
      {
        // Take the lock
        this.lock();
        try
        {    
          if (_consumerSuspended)
          {
            // clear the bit provided in the _suspendFlags
            _suspendFlags &= ~suspendFlag;
      
            if (_suspendFlags == 0) // No flags set so resume the consumer
            {
              _consumerSuspended = false;
      
              // If the consumer is still active (started) we need
              // to kickstart the consumer back into life to check for more
              // messages
              if(!closed)
                satisfiedTicks = processQueuedMsgs(null);
            }
          }
        }
        finally
        {
          this.unlock();
        }   
      }
      catch(SINotPossibleInCurrentConfigurationException e)
      {
        // No FFDC code needed
        notifyException(e);
      }
      
      if (satisfiedTicks!=null)
      {
        // inform parent about satisfied ticks - outside lock
        int length = satisfiedTicks.size();
        for (int i = 0; i < length; i++)
        {
          AORequestedTick aotick = (AORequestedTick) satisfiedTicks.get(i);
          parent.satisfiedRequest(aotick.tick, aotick.getMessage());
        }
      }
    }
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "resumeConsumer");
  }
1182352
def _install_signal_handlers(self):
        

        def stop(signum, frame):
            """
            Register scheduler's death and exit
            and remove previously acquired lock and exit.
            """
            self.log.info('Shutting down RQ scheduler...')
            self.register_death()
            self.remove_lock()
            raise SystemExit()

        signal.signal(signal.SIGINT, stop)
        signal.signal(signal.SIGTERM, stop)
1009229
def stop(self, signum=None, frame=None):
        self.debug_print("Stopping networking.")

        if self.passive is not None:
            try:
                self.passive.shutdown(1)
            except:
                pass
            self.passive.close()
            self.passive = None

        if self.last_advertise is not None:
            self.rendezvous.leave_fight()

        

        for con in self:
            con.close()

        if signum is not None:
            raise Exception("Process was interrupted.")
1270809
protected function stopping(Promised $wait) : void
    {
        $this->cls->stop();
        $this->out->stop();
        $this->agg->stop()->sync($wait);
    }
337652
def send_signal(self, signum):
        
        if self._process is None:
            raise RuntimeError('no child process')
        self._process.kill(signum)
933021
protected function sigquit()
    {
        if (Daemon::$config->logsignals->value) {
            $this->log('Caught SIGQUIT.');
        }

        $this->signalToChildren(SIGQUIT);
        $this->shutdown(SIGQUIT);
    }
448457
public function acknowledge(AMQPMessage $message)
    {
        $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']);

        if ($message->body === 'quit') {
            $message->delivery_info['channel']->basic_cancel($message->delivery_info['consumer_tag']);
        }
    }
482991
public function signalHandler($sigNo)
    {
        if ($this->isMaster) {
            static $stopCount = 0;

            switch ($sigNo) {
                case SIGINT: // Ctrl + C
                case SIGTERM:
                    $sigText = $sigNo === SIGINT ? 'SIGINT' : 'SIGTERM';
                    $this->log("Shutting down(signal:$sigText)...", ProcessLogger::PROC_INFO);
                    $this->stopWork();
                    $stopCount++;

                    if ($stopCount < 5) {
                        $this->stopWorkers();
                    } else {
                        $this->log('Stop workers failed by(signal:SIGTERM), force kill workers by(signal:SIGKILL)', ProcessLogger::PROC_INFO);
                        $this->stopWorkers(SIGKILL);
                    }
                    break;
                case SIGHUP:
                    $this->log('Restarting workers(signal:SIGHUP)', ProcessLogger::PROC_INFO);
                    $this->stopWorkers();
                    break;
                case SIGUSR1: // reload workers and reload handlers
//                    $this->log('Reloading workers and handlers(signal:SIGUSR1)', ProcessLogger::PROC_INFO);
//                    $this->stopWork();
//                    $this->start();
                    break;
                case SIGUSR2:
                    break;
                default:
                    // handle all other signals
            }

        } else {
            $this->stopWork();
            $this->log("Received 'stopWork' signal(signal:SIGTERM), will be exiting.", ProcessLogger::PROC_INFO);
        }
    }
1087777
void removeConsumer(JmsMsgConsumerImpl consumer) throws JMSException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "removeConsumer", consumer);

        // if DUPS_OK_ACKNOWLEDGE is in use, commit any messages delivered in the
        // last incomplete batch (if the session is closing it will already have
        // done this and the count of uncommitted messages will be zero)
        if ((acknowledgeMode == Session.DUPS_OK_ACKNOWLEDGE) && (uncommittedReceiveCount > 0)) {
            commitTransaction();
        }
        syncConsumers.remove(consumer);
        asyncConsumers.remove(consumer);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "removeConsumer");
    }
1185970
public static function flushBuffer($nl = false, $quit = false, array $opts = []): void
    {
        self::stopBuffer(true, $nl, $quit, $opts);
    }
694651
public function signalHandler($signalNumber)
    {
        echo 'Handling signal: #' . $signalNumber . PHP_EOL;
        global $consumer;

        switch ($signalNumber) {
            case SIGTERM:  // 15 : supervisor default stop
            case SIGQUIT:  // 3  : kill -s QUIT
                $consumer->stopHard();
                break;
            case SIGINT:   // 2  : ctrl+c
                $consumer->stop();
                break;
            case SIGHUP:   // 1  : kill -s HUP
                $consumer->restart();
                break;
            case SIGUSR1:  // 10 : kill -s USR1
                // send an alarm in 1 second
                pcntl_alarm(1);
                break;
            case SIGUSR2:  // 12 : kill -s USR2
                // send an alarm in 10 seconds
                pcntl_alarm(10);
                break;
            default:
                break;
        }
    }
999073
public function cancelReservation($rno)
    {
        $this->_checkRNO($rno);

        $digestSecret = self::digest(
            $this->colon($this->_eid, $rno, $this->_secret)
        );
        $paramList = array(
            $rno,
            $this->_eid,
            $digestSecret
        );

        self::printDebug('cancel_reservation', $paramList);

        $result = $this->xmlrpc_call('cancel_reservation', $paramList);

        return ($result == 'ok');
    }
728336
public void deregisterConsumerSetMonitor(ConnectionImpl connection,
                                           ConsumerSetChangeCallback callback)
  throws SINotPossibleInCurrentConfigurationException   
  {
    if (tc.isEntryEnabled())
        SibTr.entry(
          tc,
          "deregisterConsumerSetMonitor",
          new Object[] { connection, callback}); 

     // Call the registrar to do the work
     _consumerMonitorRegistrar.deregisterMonitor(connection, callback);
    
    if (tc.isEntryEnabled())
      SibTr.exit(tc, "deregisterConsumerSetMonitor");
 
  }