Python asyncio 模块,QueueFull() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用asyncio.QueueFull()

项目:ammoo    作者:mwfrojdman    | 项目源码 | 文件源码
def _dispatch_message(self, message: AbstractMessage):
        cam = message.cam
        if cam == BASIC_GET_OK_CAM:
            try:
                future = self._cam_waiters[cam].popleft()
            except IndexError:
                raise UnexpectedFrame(message)  # XXX: exception expects a frame, not a message?
            if not future.done():
                future.set_result(message)
        elif cam == BASIC_DELIVER_CAM:
            consumer_tag = message.consumer_tag
            logger.debug('Dispatching basic.deliver message to consumer with tag %s', consumer_tag)
            self._dispatch_to_consumer(message, consumer_tag)
        elif message.cam == BASIC_RETURN_CAM:
            if self._returned_messages_queue is not None:
                try:
                    self._returned_messages_queue.put_nowait(message)
                except QueueFull:
                    logger.warning('Received a basic.return message, but could not put it to full queue')
        else:
            raise ValueError(message)
项目:FlapJack-Cogs    作者:flapjax    | 项目源码 | 文件源码
def enqueue_tts(self, vchan: discord.Channel,
                           text: str,
                            vol: int=None,
                       priority: int=5,
                          tchan: discord.Channel=None,
                       language: str=None):
        if vol is None:
            vol = self.tts_volume
        if language is None:
            language = self.language
        tts = gTTS(text=text, lang=language)
        path = self.temp_filepath + ''.join(random.choice(
                   '0123456789ABCDEF') for i in range(12)) + ".mp3"
        tts.save(path)

        try:
            item = {'cid': vchan.id, 'path': path, 'vol': vol,
                    'priority': priority, 'delete': True, 'tchan': tchan}
            self.master_queue.put_nowait(item)
            return True
        except asyncio.QueueFull:
            return False
项目:annotated-py-asyncio    作者:hhstore    | 项目源码 | 文件源码
def test_nonblocking_put_exception(self):
        q = asyncio.Queue(maxsize=1, loop=self.loop)
        q.put_nowait(1)
        self.assertRaises(asyncio.QueueFull, q.put_nowait, 2)
项目:annotated-py-asyncio    作者:hhstore    | 项目源码 | 文件源码
def test_float_maxsize(self):
        q = asyncio.Queue(maxsize=1.3, loop=self.loop)
        q.put_nowait(1)
        q.put_nowait(2)
        self.assertTrue(q.full())
        self.assertRaises(asyncio.QueueFull, q.put_nowait, 3)

        q = asyncio.Queue(maxsize=1.3, loop=self.loop)
        @asyncio.coroutine
        def queue_put():
            yield from q.put(1)
            yield from q.put(2)
            self.assertTrue(q.full())
        self.loop.run_until_complete(queue_put())
项目:aiopubsub    作者:qntln    | 项目源码 | 文件源码
def publish(self, key: Key, message: Any) -> None:
        '''
        :raises: asyncio.QueueFull if any of the subscribers' queues overflows - FIXME - should we handle this more gracefully?
        '''
        for sub_key, qs in self._subscribers.items():
            if key.is_subset_of(sub_key):
                for q in qs:
                    q.put_nowait((key, message))
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_nonblocking_put_exception(self):
        q = asyncio.Queue(maxsize=1, loop=self.loop)
        q.put_nowait(1)
        self.assertRaises(asyncio.QueueFull, q.put_nowait, 2)
项目:ouroboros    作者:pybee    | 项目源码 | 文件源码
def test_float_maxsize(self):
        q = asyncio.Queue(maxsize=1.3, loop=self.loop)
        q.put_nowait(1)
        q.put_nowait(2)
        self.assertTrue(q.full())
        self.assertRaises(asyncio.QueueFull, q.put_nowait, 3)

        q = asyncio.Queue(maxsize=1.3, loop=self.loop)
        @asyncio.coroutine
        def queue_put():
            yield from q.put(1)
            yield from q.put(2)
            self.assertTrue(q.full())
        self.loop.run_until_complete(queue_put())
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_nonblocking_put_exception(self):
        q = asyncio.Queue(maxsize=1, loop=self.loop)
        q.put_nowait(1)
        self.assertRaises(asyncio.QueueFull, q.put_nowait, 2)
项目:kbe_server    作者:xiaohaoppy    | 项目源码 | 文件源码
def test_float_maxsize(self):
        q = asyncio.Queue(maxsize=1.3, loop=self.loop)
        q.put_nowait(1)
        q.put_nowait(2)
        self.assertTrue(q.full())
        self.assertRaises(asyncio.QueueFull, q.put_nowait, 3)

        q = asyncio.Queue(maxsize=1.3, loop=self.loop)
        @asyncio.coroutine
        def queue_put():
            yield from q.put(1)
            yield from q.put(2)
            self.assertTrue(q.full())
        self.loop.run_until_complete(queue_put())
项目:FlapJack-Cogs    作者:flapjax    | 项目源码 | 文件源码
def enqueue_sfx(self, vchan: discord.Channel,
                           path: str,
                            vol: int=None,
                       priority: int=5,
                         delete: bool=False,
                          tchan: discord.Channel=None):
        if vol is None:
            vol = self.default_volume
        try:
            item = {'cid': vchan.id, 'path': path, 'vol': vol,
                    'priority': priority, 'delete': delete, 'tchan': tchan}
            self.master_queue.put_nowait(item)
            return True
        except asyncio.QueueFull:
            return False
项目:FlapJack-Cogs    作者:flapjax    | 项目源码 | 文件源码
def _queue_manager(self):
        await self.bot.wait_until_ready()
        while True:
            await asyncio.sleep(0.1)
            # First check for empty queues
            for slave in self.slave_tasks:
                if (self.slave_tasks[slave] is not None and
                        self.slave_tasks[slave].done()):
                    # Task is not completed until:
                    # Slave queue is empty, and timeout is reached /
                    # vc disconnected / someone else stole vc
                    self.slave_tasks[slave] = None
                    self.slave_queues[slave] = None

            # Next we can check for new items
            item = None
            try:
                item = self.master_queue.get_nowait()
            except asyncio.QueueEmpty:
                continue
            # This does not really check to make sure the queued item
            # is valid. Should probably check that with the enqueue function.
            channel = self.bot.get_channel(item['cid'])
            server = channel.server
            sid = server.id
            priority = item['priority']

            if self.slave_tasks.get(sid) is None:
                # Create slave queue
                queue = asyncio.Queue(maxsize=20)
                self.slave_queues[sid] = queue
                self.slave_tasks[sid] = self.bot.loop.create_task(
                                            self._slave_queue_manager(queue,
                                                                        sid))
            try:
                self.slave_queues[sid].put_nowait(item)
            except asyncio.QueueFull:
                # It's possible to add a way to handle full queue situation.
                pass
        # Need to add cancelled task exception handler?