当前位置: 首页>>代码示例>>Python>>正文


Python OrderedDict.clear方法代码示例

本文整理汇总了Python中synnefo.lib.ordereddict.OrderedDict.clear方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.clear方法的具体用法?Python OrderedDict.clear怎么用?Python OrderedDict.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在synnefo.lib.ordereddict.OrderedDict的用法示例。


在下文中一共展示了OrderedDict.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: AMQPPukaClient

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import clear [as 别名]

#.........这里部分代码省略.........

        if self.confirms:
            self.unacked[promise] = (exchange, routing_key, body)

        return promise

    def handle_publisher_confirm(self, promise, result):
        """Handle publisher confirmation message.

        Callback function which handles publisher confirmation by removing
        the promise (and message) from 'unacked' messages.

        """
        msg = self.unacked.pop(promise, None)
        if msg is None:
            self.log.warning("Received publisher confirmation for"
                             " unknown promise '%s'", promise)

    @reconnect_decorator
    def flush_buffer(self):
        while self.client.needs_write():
            self.client.on_write()

    @reconnect_decorator
    def get_confirms(self):
        """Wait for all publisher confirmations."""
        while self.unacked:
            self.client.wait(self.unacked.keys())

    @reconnect_decorator
    def _resend_unacked_messages(self):
        """Resend unacked messages in case of a connection failure."""
        msgs = self.unacked.values()
        self.unacked.clear()
        for exchange, routing_key, body in msgs:
            self.log.debug('Resending message %s' % body)
            self.basic_publish(exchange, routing_key, body)

    @reconnect_decorator
    def _resend_unsend_messages(self):
        """Resend unsend messages in case of a connection failure."""
        for body in self.unsend.keys():
            (exchange, routing_key) = self.unsend[body]
            self.basic_publish(exchange, routing_key, body)
            self.unsend.pop(body)

    @reconnect_decorator
    def basic_consume(self, queue, callback, no_ack=False, prefetch_count=0):
        """Consume from a queue.

        @type queue: string or list of strings
        @param queue: the name or list of names from the queues to consume
        @type callback: function
        @param callback: the callback function to run when a message arrives

        """
        self.log.debug("Consume from queue '%s'", queue)
        # Store the queues and the callback
        self.consumers[queue] = callback

        def handle_delivery(promise, msg):
            """Hide promises and messages without body"""
            if 'body' in msg:
                callback(self, msg)
            else:
                self.log.debug("Message without body %s" % msg)
开发者ID:AthinaB,项目名称:synnefo,代码行数:70,代码来源:amqp_puka.py

示例2: AMQPHaighaClient

# 需要导入模块: from synnefo.lib.ordereddict import OrderedDict [as 别名]
# 或者: from synnefo.lib.ordereddict.OrderedDict import clear [as 别名]

#.........这里部分代码省略.........
        self.channel.queue.declare(queue, durable=True, exclusive=exclusive,
                                   auto_delete=False, arguments=arguments)

    def queue_bind(self, queue, exchange, routing_key):
        logger.info('Binding queue %s to exchange %s with key %s', queue,
                    exchange, routing_key)
        self.channel.queue.bind(queue=queue, exchange=exchange,
                                routing_key=routing_key)

    def _confirm_select(self):
        logger.info('Setting channel to confirm mode')
        self.channel.confirm.select()
        self.channel.basic.set_ack_listener(self._ack_received)
        self.channel.basic.set_nack_listener(self._nack_received)

    @reconnect_decorator
    def basic_publish(self, exchange, routing_key, body):
        msg = Message(body, delivery_mode=2)
        mid = self.channel.basic.publish(msg, exchange, routing_key)
        if self.confirms:
            self.unacked[mid] = (exchange, routing_key, body)
            if len(self.unacked) > self.confirm_buffer:
                self.get_confirms()

        logger.debug('Published message %s with id %s', body, mid)

    @reconnect_decorator
    def get_confirms(self):
        self.connection.read_frames()

    @reconnect_decorator
    def _resend_unacked_messages(self):
        msgs = self.unacked.values()
        self.unacked.clear()
        for exchange, routing_key, body in msgs:
            logger.debug('Resending message %s', body)
            self.basic_publish(exchange, routing_key, body)

    @reconnect_decorator
    def _ack_received(self, mid):
        print mid
        logger.debug('Received ACK for message with id %s', mid)
        self.unacked.pop(mid)

    @reconnect_decorator
    def _nack_received(self, mid):
        logger.error('Received NACK for message with id %s. Retrying.', mid)
        (exchange, routing_key, body) = self.unacked[mid]
        self.basic_publish(exchange, routing_key, body)

    def basic_consume(self, queue, callback, no_ack=False, exclusive=False):
        """Consume from a queue.

        @type queue: string or list of strings
        @param queue: the name or list of names from the queues to consume
        @type callback: function
        @param callback: the callback function to run when a message arrives

        """

        self.consumers[queue] = callback
        self.channel.basic.consume(queue, consumer=callback, no_ack=no_ack,
                                   exclusive=exclusive)

    @reconnect_decorator
    def basic_wait(self):
开发者ID:grnet,项目名称:synnefo,代码行数:70,代码来源:amqp_haigha.py


注:本文中的synnefo.lib.ordereddict.OrderedDict.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。