summaryrefslogtreecommitdiff
path: root/eventlet/queue.py
diff options
context:
space:
mode:
authorRyan Williams <rdw@lindenlab.com>2010-01-23 20:57:42 -0500
committerRyan Williams <rdw@lindenlab.com>2010-01-23 20:57:42 -0500
commit66ea48836deb62d3642e9b90b740100a00df75a4 (patch)
treea88d4283a9b2fb8f11b7fd977b64c38b31543332 /eventlet/queue.py
parentde57fcd8ab03094b4e8c5baf9bdedf6956323e3c (diff)
downloadeventlet-66ea48836deb62d3642e9b90b740100a00df75a4.tar.gz
Added getting() and putting() methods to the Queue class, replaced coros.queue with queue.Queue in pools.py.
Diffstat (limited to 'eventlet/queue.py')
-rw-r--r--eventlet/queue.py27
1 files changed, 23 insertions, 4 deletions
diff --git a/eventlet/queue.py b/eventlet/queue.py
index 9e26cf8..cb655ec 100644
--- a/eventlet/queue.py
+++ b/eventlet/queue.py
@@ -1,13 +1,22 @@
# Copyright (c) 2009 Denis Bilenko. See LICENSE for details.
"""Synchronized queues.
-The :mod:`eventlet.queue` module implements multi-producer, multi-consumer queues that work across greenlets, with the API similar to the classes found in the standard :mod:`Queue` and :class:`multiprocessing <multiprocessing.Queue>` modules.
+The :mod:`eventlet.queue` module implements multi-producer, multi-consumer
+queues that work across greenlets, with the API similar to the classes found in
+the standard :mod:`Queue` and :class:`multiprocessing <multiprocessing.Queue>`
+modules.
A major difference is that queues in this module operate as channels when
initialized with *maxsize* of zero. In such case, both :meth:`Queue.empty`
-and :meth:`Queue.full` return ``True`` and :meth:`Queue.put` always blocks until a call to :meth:`Queue.get` retrieves the item.
-
-Another interesting difference is that :meth:`Queue.qsize`, :meth:`Queue.empty`, and :meth:`Queue.full` *can* be used as indicators of whether the subsequent :meth:`Queue.get` or :meth:`Queue.put` will not block.
+and :meth:`Queue.full` return ``True`` and :meth:`Queue.put` always blocks until
+a call to :meth:`Queue.get` retrieves the item.
+
+An interesting difference, made possible because of greenthreads, is
+that :meth:`Queue.qsize`, :meth:`Queue.empty`, and :meth:`Queue.full` *can* be
+used as indicators of whether the subsequent :meth:`Queue.get`
+or :meth:`Queue.put` will not block. The new methods :meth:`Queue.getting`
+and :meth:`Queue.putting` report on the number of greenthreads blocking
+in :meth:`put <Queue.put>` or :meth:`get <Queue.get>` respectively.
"""
import sys
@@ -149,6 +158,16 @@ class LightQueue(object):
def qsize(self):
"""Return the size of the queue."""
return len(self.queue)
+
+ def putting(self):
+ """Returns the number of greenthreads that are blocked waiting to put
+ items into the queue."""
+ return len(self.putters)
+
+ def getting(self):
+ """Returns the number of greenthreads that are blocked waiting on an
+ empty queue."""
+ return len(self.getters)
def empty(self):
"""Return ``True`` if the queue is empty, ``False`` otherwise."""