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