Commit 42d87352 authored by Jason Madden's avatar Jason Madden

doc tweaks [skip ci]

parent 4d85f51e
:mod:`gevent.queue` -- Synchronized queues ============================================
========================================== :mod:`gevent.queue` -- Synchronized queues
============================================
.. automodule:: gevent.queue .. automodule:: gevent.queue
:members: :members:
:undoc-members: :undoc-members:
.. exception:: Full .. exception:: Full
...@@ -13,6 +14,9 @@ ...@@ -13,6 +14,9 @@
An alias for :class:`Queue.Empty` An alias for :class:`Queue.Empty`
Examples
========
Example of how to wait for enqueued tasks to be completed:: Example of how to wait for enqueued tasks to be completed::
def worker(): def worker():
...@@ -31,4 +35,3 @@ Example of how to wait for enqueued tasks to be completed:: ...@@ -31,4 +35,3 @@ Example of how to wait for enqueued tasks to be completed::
q.put(item) q.put(item)
q.join() # block until all tasks are done q.join() # block until all tasks are done
...@@ -339,6 +339,7 @@ killing will remain blocked forever). ...@@ -339,6 +339,7 @@ killing will remain blocked forever).
`This document `This document
<http://docs.oracle.com/javase/8/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html>`_ <http://docs.oracle.com/javase/8/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html>`_
describes a similar situation for threads. describes a similar situation for threads.
Timeouts Timeouts
======== ========
...@@ -364,7 +365,7 @@ add timeouts to arbitrary sections of (cooperative, yielding) code. ...@@ -364,7 +365,7 @@ add timeouts to arbitrary sections of (cooperative, yielding) code.
Further reading Further reading
============== ===============
To limit concurrency, use the :class:`gevent.pool.Pool` class (see `example: dns_mass_resolve.py`_). To limit concurrency, use the :class:`gevent.pool.Pool` class (see `example: dns_mass_resolve.py`_).
......
# Copyright (c) 2009-2012 Denis Bilenko. See LICENSE for details. # Copyright (c) 2009-2012 Denis Bilenko. See LICENSE for details.
"""Synchronized queues. """
Synchronized queues.
The :mod:`gevent.queue` module implements multi-producer, multi-consumer queues The :mod:`gevent.queue` module implements multi-producer, multi-consumer queues
that work across greenlets, with the API similar to the classes found in the that work across greenlets, with the API similar to the classes found in the
standard :mod:`Queue` and :class:`multiprocessing <multiprocessing.Queue>` modules. standard :mod:`Queue` and :class:`multiprocessing <multiprocessing.Queue>` modules.
The classes in this module implement iterator protocol. Iterating over queue The classes in this module implement the iterator protocol. Iterating
means repeatedly calling :meth:`get <Queue.get>` until :meth:`get <Queue.get>` returns ``StopIteration``. over a queue means repeatedly calling :meth:`get <Queue.get>` until
:meth:`get <Queue.get>` returns ``StopIteration`` (specifically that
class, not an instance or subclass).
>>> queue = gevent.queue.Queue() >>> queue = gevent.queue.Queue()
>>> queue.put(1) >>> queue.put(1)
...@@ -58,11 +61,14 @@ class Queue(object): ...@@ -58,11 +61,14 @@ class Queue(object):
If *maxsize* is less than or equal to zero or ``None``, the queue If *maxsize* is less than or equal to zero or ``None``, the queue
size is infinite. size is infinite.
Queues have a ``len`` equal to the number of items in them (the :meth:`qsize`),
but in a boolean context they are always True.
.. versionchanged:: 1.1b3 .. versionchanged:: 1.1b3
Queues now support :func:`len`; it behaves the same as :meth:`qsize`. Queues now support :func:`len`; it behaves the same as :meth:`qsize`.
.. versionchanged:: 1.1b3 .. versionchanged:: 1.1b3
Multiple greenlets that block on a call to :meth:`put` for a full queue Multiple greenlets that block on a call to :meth:`put` for a full queue
will now be woken up to put their items into the queue in the order in which will now be awakened to put their items into the queue in the order in which
they arrived. Likewise, multiple greenlets that block on a call to :meth:`get` for they arrived. Likewise, multiple greenlets that block on a call to :meth:`get` for
an empty queue will now receive items in the order in which they blocked. An an empty queue will now receive items in the order in which they blocked. An
implementation quirk under CPython *usually* ensured this was roughly the case implementation quirk under CPython *usually* ensured this was roughly the case
...@@ -74,8 +80,10 @@ class Queue(object): ...@@ -74,8 +80,10 @@ class Queue(object):
self.maxsize = None self.maxsize = None
if maxsize == 0: if maxsize == 0:
import warnings import warnings
warnings.warn('Queue(0) now equivalent to Queue(None); if you want a channel, use Channel', warnings.warn(
DeprecationWarning, stacklevel=2) 'Queue(0) now equivalent to Queue(None); if you want a channel, use Channel',
DeprecationWarning,
stacklevel=2)
else: else:
self.maxsize = maxsize self.maxsize = maxsize
# Explicitly maintain order for getters and putters that block # Explicitly maintain order for getters and putters that block
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment