|
| 1 | +\section{Standard module \sectcode{Queue}} |
| 2 | +\stmodindex{Queue} |
| 3 | + |
| 4 | +\label{module-Queue} |
| 5 | + |
| 6 | +% ==== 2. ==== |
| 7 | +% Give a short overview of what the module does. |
| 8 | +% If it is platform specific, mention this. |
| 9 | +% Mention other important restrictions or general operating principles. |
| 10 | +% For example: |
| 11 | + |
| 12 | +The \code{Queue} module implements a multi-producer, multi-consumer |
| 13 | +FIFO queue. It is especially useful in threads programming when |
| 14 | +information must be exchanged safely between multiple threads. The |
| 15 | +\code{Queue} class in this module implements all the required locking |
| 16 | +semantics. It depends on the availability of thread support in |
| 17 | +Python. |
| 18 | + |
| 19 | +The \code{Queue} module defines the following exception: |
| 20 | + |
| 21 | +\renewcommand{\indexsubitem}{(in module Queue)} |
| 22 | + |
| 23 | +\begin{excdesc}{Empty} |
| 24 | +Exception raised when non-blocking get (e.g. \code{get_nowait()}) is |
| 25 | +called on a Queue object which is empty, or for which the emptyiness |
| 26 | +cannot be determined (i.e. because the appropriate locks cannot be |
| 27 | +acquired). |
| 28 | +\end{excdesc} |
| 29 | + |
| 30 | +\subsection{Queue Objects} |
| 31 | + |
| 32 | +Class \code{Queue} implements queue objects and has the methods |
| 33 | +described below. This class can be derived from in order to implement |
| 34 | +other queue organizations (e.g. stack) but the inheritable interface |
| 35 | +is not described here. See the source code for details. The public |
| 36 | +interface methods are: |
| 37 | + |
| 38 | +\renewcommand{\indexsubitem}{(__init__ method)} |
| 39 | + |
| 40 | +\begin{funcdesc}{__init__}{maxsize} |
| 41 | +Constructor for the class. \var{maxsize} is an integer that sets the |
| 42 | +upperbound limit on the number of items that can be placed in the |
| 43 | +queue. Insertion will block once this size has been reached, until |
| 44 | +queue items are consumed. If \var{maxsize} is less than or equal to |
| 45 | +zero, the queue size is infinite. |
| 46 | +\end{funcdesc} |
| 47 | + |
| 48 | +\renewcommand{\indexsubitem}{(qsize method)} |
| 49 | + |
| 50 | +\begin{funcdesc}{qsize}{} |
| 51 | +Returns the approximate size of the queue. Because of multithreading |
| 52 | +semantics, this number is not reliable. |
| 53 | +\end{funcdesc} |
| 54 | + |
| 55 | +\renewcommand{\indexsubitem}{(empty method)} |
| 56 | + |
| 57 | +\begin{funcdesc}{empty}{} |
| 58 | +Returns 1 if the queue is empty, 0 otherwise. Because of |
| 59 | +multithreading semantics, this is not reliable. |
| 60 | +\end{funcdesc} |
| 61 | + |
| 62 | +\renewcommand{\indexsubitem}{(full method)} |
| 63 | + |
| 64 | +\begin{funcdesc}{full}{} |
| 65 | +Returns 1 if the queue is full, 0 otherwise. Because of |
| 66 | +multithreading semantics, this is not reliable. |
| 67 | +\end{funcdesc} |
| 68 | + |
| 69 | +\renewcommand{\indexsubitem}{(put method)} |
| 70 | + |
| 71 | +\begin{funcdesc}{put}{item} |
| 72 | +Puts \var{item} into the queue. |
| 73 | +\end{funcdesc} |
| 74 | + |
| 75 | +\renewcommand{\indexsubitem}{(get method)} |
| 76 | + |
| 77 | +\begin{funcdesc}{get}{} |
| 78 | +Gets and returns an item from the queue, blocking if necessary until |
| 79 | +one is available. |
| 80 | +\end{funcdesc} |
| 81 | + |
| 82 | +\renewcommand{\indexsubitem}{(get_nowait method)} |
| 83 | + |
| 84 | +\begin{funcdesc}{get_nowait}{} |
| 85 | +Gets and returns an item from the queue if one is immediately |
| 86 | +available. Raises an \code{Empty} exception if the queue is empty or |
| 87 | +if the queue's emptiness cannot be determined. |
| 88 | +\end{funcdesc} |
0 commit comments