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


Python queue.Queue类代码示例

本文整理汇总了Python中eventlet.queue.Queue的典型用法代码示例。如果您正苦于以下问题:Python Queue类的具体用法?Python Queue怎么用?Python Queue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: EventletInbox

class EventletInbox(object):
    def __init__(self, logger=None):
        ''' __init__ '''

        self.__inbox = EventletQueue()

        if logger is None:
            self._logger = getLogger('%s.EventletInbox' % __name__)
        else:
            self._logger = logger

    def get(self):
        ''' get data from inbox '''
        try:
            result = self.__inbox.get_nowait()
        except EventletEmpty:
            raise EmptyInboxException
        return result

    def put(self, message):
        ''' put message to inbox '''

        self.__inbox.put(message)

    def __len__(self):
        ''' return length of inbox '''

        return self.__inbox.qsize()
开发者ID:snakeego,项目名称:pyactors,代码行数:28,代码来源:event.py

示例2: _make_app_iter

    def _make_app_iter(self, node, source):
        """
        Returns an iterator over the contents of the source (via its read
        func).  There is also quite a bit of cleanup to ensure garbage
        collection works and the underlying socket of the source is closed.

        :param source: The httplib.Response object this iterator should read
                       from.
        :param node: The node the source is reading from, for logging purposes.
        """
        try:
            # Spawn reader to read from the source and place in the queue.
            # We then drop any reference to the source or node, for garbage
            # collection purposes.
            queue = Queue(1)
            spawn_n(self._make_app_iter_reader, node, source, queue,
                    self.app.logger.thread_locals)
            source = node = None
            while True:
                chunk = queue.get(timeout=self.app.node_timeout)
                if isinstance(chunk, bool):  # terminator
                    success = chunk
                    if not success:
                        raise Exception(_('Failed to read all data'
                                          ' from the source'))
                    break
                yield chunk
        except Empty:
            raise ChunkReadTimeout()
        except (GeneratorExit, Timeout):
            self.app.logger.warn(_('Client disconnected on read'))
        except Exception:
            self.app.logger.exception(_('Trying to send to client'))
            raise
开发者ID:sa4250mnpo70,项目名称:swift,代码行数:34,代码来源:base.py

示例3: __init__

    def __init__(self):
        self.queue_send = Queue()
        self.queue_recv = Queue()
        self.appid = None

        # interface
        self.sock = None
开发者ID:patamushta,项目名称:scp,代码行数:7,代码来源:sockwraps.py

示例4: LocalMailbox

class LocalMailbox(Mailbox):

    def __init__(self):
        self._queue = Queue()

    def put(self, message):
        self._queue.put(message)

    def get(self):
        return self._queue.get()
开发者ID:ahmetus,项目名称:mochi,代码行数:10,代码来源:mailbox.py

示例5: MethodReader

class MethodReader(object):
    """
    Helper class to receive frames from the broker, combine them if
    necessary with content-headers and content-bodies into complete methods.

    Normally a method is represented as a tuple containing
    (channel, method_sig, args, content).

    In the case of a framing error, an AMQPConnectionException is placed
    in the queue.

    In the case of unexpected frames, a tuple made up of
    (channel, AMQPChannelException) is placed in the queue.

    """
    def __init__(self, source):
        self.source = source
        self.queue = Queue()
        self.running = False
        self.partial_messages = {}
        # For each channel, which type is expected next
        self.expected_types = defaultdict(lambda:1)


    def _next_method(self):
        """
        Read the next method from the source, once one complete method has
        been assembled it is placed in the internal queue.

        """
        while self.queue.empty():
            try:
                frame_type, channel, payload = self.source.read_frame()
            except Exception, e:
                #
                # Connection was closed?  Framing Error?
                #
                self.queue.put(e)
                break

            if self.expected_types[channel] != frame_type:
                self.queue.put((
                    channel,
                    Exception('Received frame type %s while expecting type: %s' %
                        (frame_type, self.expected_types[channel])
                        )
                    ))
            elif frame_type == 1:
                self._process_method_frame(channel, payload)
            elif frame_type == 2:
                self._process_content_header(channel, payload)
            elif frame_type == 3:
                self._process_content_body(channel, payload)
开发者ID:jab,项目名称:greenamqp,代码行数:53,代码来源:method_framing.py

示例6: __init__

 def __init__(self, id_):
     self.id = id_
     self._peers = {}
     self.peers_info = {}
     self.available_peers = []
     self.main_channel = PriorityQueue()
     self.data_channel = Queue(1)
     self.sending_queue = Queue()
     self.receiving_queue = Queue()
     self.buffer = {}
     # for stats
     self.sent_bytes = 0
     self.received_bytes = 0
     self.delays = {}
开发者ID:AAzza,项目名称:overlay-network,代码行数:14,代码来源:node.py

示例7: __init__

    def __init__(self, *args, **kwargs):
        Connection.__init__(self, *args, **kwargs)

        self._write_queue = Queue()

        sockerr = None
        addresses = socket.getaddrinfo(
            self.host, self.port, socket.AF_UNSPEC, socket.SOCK_STREAM
        )
        for (af, socktype, proto, canonname, sockaddr) in addresses:
            try:
                self._socket = socket.socket(af, socktype, proto)
                self._socket.settimeout(1.0)
                self._socket.connect(sockaddr)
                sockerr = None
                break
            except socket.error as err:
                sockerr = err
        if sockerr:
            raise socket.error(
                sockerr.errno,
                "Tried connecting to %s. Last error: %s" % (
                    [a[4] for a in addresses], sockerr.strerror)
            )

        if self.sockopts:
            for args in self.sockopts:
                self._socket.setsockopt(*args)

        self._read_watcher = eventlet.spawn(lambda: self.handle_read())
        self._write_watcher = eventlet.spawn(lambda: self.handle_write())
        self._send_options_message()
开发者ID:kjy,项目名称:python-driver,代码行数:32,代码来源:eventletreactor.py

示例8: __init__

 def __init__(self, source):
     self.source = source
     self.queue = Queue()
     self.running = False
     self.partial_messages = {}
     # For each channel, which type is expected next
     self.expected_types = defaultdict(lambda:1)
开发者ID:jab,项目名称:greenamqp,代码行数:7,代码来源:method_framing.py

示例9: __init__

    def __init__(self, settings):
        self.temp_dir = settings['temp_dir']
        self.download_path = settings['download_path']
        self.connection_pool = Queue(settings['connections'])

        for _ in xrange(settings['connections']):
            self.connection_pool.put(NNTP(settings['host'], settings['port'], settings['username'], settings['password']))
开发者ID:sww,项目名称:itchynzb,代码行数:7,代码来源:download.py

示例10: Actor

class Actor(ActorBase):
    def __init__(self, callback):
        self._inbox = Queue()
        self._callback = callback
        self._greenlet = None

    def run(self, *args, **kwargs):
        greenlet_id = id(eventlet.getcurrent())
        _actor_map[greenlet_id] = self
        try:
            self._callback(*args, **kwargs)
        finally:
            del _actor_map[greenlet_id]

    def spawn(self, *args, **kwargs):
        self._greenlet = _actor_pool.spawn(self.run, *args, **kwargs)

    def link(self, func, *args, **kwargs):
        if self._greenlet is None:
            return
        return self._greenlet.link(func, *args, **kwargs)

    def unlink(self, func, *args, **kwargs):
        if self._greenlet is None:
            return
        return self._greenlet.unlink(func, *args, **kwargs)

    def cancel(self, *throw_args):
        if self._greenlet is None:
            return
        return self._greenlet.cancel(*throw_args)

    def kill(self, *throw_args):
        if self._greenlet is None:
            return
        return self._greenlet.kill(*throw_args)

    def wait(self):
        if self._greenlet is None:
            return
        return self._greenlet.wait()

    def send(self, message):
        self._inbox.put(message)

    def receive(self):
        return self._inbox.get()
开发者ID:tlvu,项目名称:mochi,代码行数:47,代码来源:actor.py

示例11: __init__

 def __init__(self, *args, **kwargs):
     super(Client, self).__init__(*args, **kwargs)
     self.pool = eventlet.greenpool.GreenPool(DEFAULT_POOL_SIZE)
     self.reader_thread = None
     self.writer_thread = None
     self.queue = Queue(DEFAULT_MAX_QUEUE_SIZE)
     self.max_pending = MAX_PENDING
     self.closing = False
开发者ID:kinjalcpatel,项目名称:kinetic-py,代码行数:8,代码来源:greenclient.py

示例12: LocalMailbox

class LocalMailbox(Mailbox):

    def __init__(self):
        self._queue = Queue()

    def put(self, message):
        self._queue.put(message)

    def get(self):
        return self._queue.get()

    def encode(self):
        raise NotImplementedError

    @staticmethod
    def decode(params):
        raise NotImplementedError
开发者ID:HOLYCOWBATMAN,项目名称:mochi,代码行数:17,代码来源:mailbox.py

示例13: __init__

    def __init__(self, *args, **kwargs):
        Connection.__init__(self, *args, **kwargs)
        self._write_queue = Queue()

        self._connect_socket()

        self._read_watcher = eventlet.spawn(lambda: self.handle_read())
        self._write_watcher = eventlet.spawn(lambda: self.handle_write())
        self._send_options_message()
开发者ID:datastax,项目名称:python-driver,代码行数:9,代码来源:eventletreactor.py

示例14: __init__

    def __init__(self, logger=None):
        ''' __init__ '''

        self.__inbox = EventletQueue()

        if logger is None:
            self._logger = getLogger('%s.EventletInbox' % __name__)
        else:
            self._logger = logger
开发者ID:snakeego,项目名称:pyactors,代码行数:9,代码来源:event.py

示例15: wait

 def wait(self):
     """The difference from Queue.wait: if there is an only item in the
     Queue and it is an exception, raise it, but keep it in the Queue, so
     that future calls to wait() will raise it again.
     """
     if self.has_error() and len(self.items) == 1:
         # the last item, which is an exception, raise without emptying the Queue
         getcurrent().throw(*self.items[0][1])
     else:
         return Queue.wait(self)
开发者ID:hardys,项目名称:eventlet,代码行数:10,代码来源:protocol.py


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