Python stop consuming

17 Python code examples are found related to " stop consuming". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: consumer.py    From django-carrot with Apache License 2.0 6 votes vote down vote up
def stop_consuming(self) -> None:
        """
        Stops all running threads. Loops through the threads twice - firstly, to set the signal to **False** on all
        threads, secondly to wait for them all to finish

        If a single loop was used here, the latter threads could still consume new tasks while the parent process waited
        for the earlier threads to finish. The second loop allows for quicker consumer stoppage and stops all consumers
        from consuming new tasks from the moment the signal is received
        """
        for t in self.threads:
            t.stop()

        for t in self.threads:
            print('Closing consumer %s' % t)
            t.join()
            print('Closed consumer %s' % t) 
Example 2
Source File: eventlib.py    From event-driven-microservice with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def stop_consuming_events(topic):
    """
    Notify the consumer's flag that it is
    not running any longer.

    The consumer will properly terminate at its
    next iteration.
    """
    if topic and topic in consumers:
        consumer = consumers[topic]
        consumer.stop()
        while topic in consumers:
            await asyncio.sleep(0.1) 
Example 3
Source File: amqp_async_consumer.py    From resilient-community-apps with MIT License 5 votes vote down vote up
def stop_consuming(self):
        """Tell RabbitMQ that you would like to stop consuming by sending the
        Basic.Cancel RPC command.

        """
        if self._channel:
            log.info('Sending a Basic.Cancel RPC command to RabbitMQ')
            self._channel.basic_cancel(self.on_cancelok, self._consumer_tag) 
Example 4
Source File: channel.py    From amqpstorm with MIT License 5 votes vote down vote up
def stop_consuming(self):
        """Stop consuming messages.

        :raises AMQPChannelError: Raises if the channel encountered an error.
        :raises AMQPConnectionError: Raises if the connection
                                     encountered an error.

        :return:
        """
        if not self.consumer_tags:
            return
        if not self.is_closed:
            for tag in self.consumer_tags:
                self.basic.cancel(tag)
        self.remove_consumer_tag() 
Example 5
Source File: abstract.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def stopConsuming(self):
        """Stop consuming data.

        This is called when a producer has lost its connection, to tell the
        consumer to go lose its connection (and break potential circular
        references).
        """
        self.unregisterProducer()
        self.loseConnection()

    # producer interface implementation 
Example 6
Source File: pika_rabbit.py    From FFXIVBOT with GNU General Public License v3.0 5 votes vote down vote up
def stop_consuming(self):
        """Tell RabbitMQ that you would like to stop consuming by sending the
        Basic.Cancel RPC command.

        """
        if self._channel:
            LOGGER.info("Sending a Basic.Cancel RPC command to RabbitMQ")
            self._channel.basic_cancel(self.on_cancelok, self._consumer_tag) 
Example 7
Source File: rpc_server.py    From ab-2018 with GNU General Public License v3.0 5 votes vote down vote up
def stop_consuming(self):
        """Tell RabbitMQ that you would like to stop consuming by sending the
        Basic.Cancel RPC command.

        """
        if self._channel:
            print('Sending a Basic.Cancel RPC command to RabbitMQ')
            self._channel.basic_cancel(self.on_cancelok, self._consumer_tag) 
Example 8
Source File: consumer.py    From yabmp with Apache License 2.0 5 votes vote down vote up
def stop_consuming(self):
        """Tell RabbitMQ that you would like to stop consuming by sending the
        Basic.Cancel RPC command.

        """
        if self._channel:
            LOG.info('Sending a Basic.Cancel RPC command to RabbitMQ')
            self._channel.basic_cancel(self.on_cancelok, self._consumer_tag) 
Example 9
Source File: event_consumers.py    From SpoofcheckSelfTest with Apache License 2.0 5 votes vote down vote up
def stop_consuming(self):
        """Tell RabbitMQ that you would like to stop consuming by sending the
        Basic.Cancel RPC command.
        """
        if self._channel:
            LOGGER.info('Sending a Basic.Cancel RPC command to RabbitMQ')
            self._channel.basic_cancel(self.on_cancelok, self._consumer_tag) 
Example 10
Source File: PubSubConsumer.py    From openSUSE-release-tools with GNU General Public License v2.0 5 votes vote down vote up
def stop_consuming(self):
        """Tell RabbitMQ that you would like to stop consuming by sending the
        Basic.Cancel RPC command.

        """
        if self._channel:
            self.logger.debug('Sending a Basic.Cancel RPC command to RabbitMQ')
            cb = functools.partial(self.on_cancelok, userdata=self._consumer_tag)
            self._channel.basic_cancel(self._consumer_tag, cb) 
Example 11
Source File: MultiTopicConsumer.py    From ChaosTestingCode with MIT License 5 votes vote down vote up
def stop_consuming(self):
        self.terminate = True
        if self.is_connection_open():
            if self.last_msg != "":
                console_out(f"Requested to stop. Last msg acked: {self.last_msg}", self.get_actor())
            else:
                console_out(f"Requested to stop.", self.get_actor())
            self.disconnect()
        else:
            if self.last_msg != "":
                console_out(f"Requested to stop - connection already closed. Last msg acked: {self.last_msg}", self.get_actor())
            else:
                console_out(f"Requested to stop - connection already closed.", self.get_actor()) 
Example 12
Source File: queue.py    From zulip with Apache License 2.0 5 votes vote down vote up
def stop_consuming(self) -> None:
        self.channel.stop_consuming()

# Patch pika.adapters.tornado_connection.TornadoConnection so that a socket error doesn't
# throw an exception and disconnect the tornado process from the rabbitmq
# queue. Instead, just re-connect as usual 
Example 13
Source File: queue.py    From n6 with GNU Affero General Public License v3.0 5 votes vote down vote up
def stop_consuming(self):
        """
        From pika docs:

        Tell RabbitMQ that you would like to stop consuming by sending the
        Basic.Cancel RPC command.
        """
        if self._channel_in is not None:
            LOGGER.debug('Sending a Basic.Cancel RPC command to RabbitMQ')
            self._channel_in.basic_cancel(self.on_cancelok, self._consumer_tag)
        else:
            LOGGER.warning(
                'input queue consuming cannot be cancelled properly '
                'because input channel is already None')
            ## XXX: restart or what?