blob: f6aa31e59555539a86968fe5a7b01d3c185d57e5 [file] [log] [blame]
Fred Drake9c483191997-12-17 14:08:01 +00001\section{Standard Module \sectcode{Queue}}
Barry Warsaw17c8e781997-11-20 19:54:16 +00002\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
Fred Drake19479911998-02-13 06:58:54 +000021\setindexsubitem{(in module Queue)}
Barry Warsaw17c8e781997-11-20 19:54:16 +000022
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
Fred Drake19479911998-02-13 06:58:54 +000038\setindexsubitem{(__init__ method)}
Barry Warsaw17c8e781997-11-20 19:54:16 +000039
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
Fred Drake19479911998-02-13 06:58:54 +000048\setindexsubitem{(qsize method)}
Barry Warsaw17c8e781997-11-20 19:54:16 +000049
50\begin{funcdesc}{qsize}{}
51Returns the approximate size of the queue. Because of multithreading
52semantics, this number is not reliable.
53\end{funcdesc}
54
Fred Drake19479911998-02-13 06:58:54 +000055\setindexsubitem{(empty method)}
Barry Warsaw17c8e781997-11-20 19:54:16 +000056
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
Fred Drake19479911998-02-13 06:58:54 +000062\setindexsubitem{(full method)}
Barry Warsaw17c8e781997-11-20 19:54:16 +000063
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
Fred Drake19479911998-02-13 06:58:54 +000069\setindexsubitem{(put method)}
Barry Warsaw17c8e781997-11-20 19:54:16 +000070
71\begin{funcdesc}{put}{item}
72Puts \var{item} into the queue.
73\end{funcdesc}
74
Fred Drake19479911998-02-13 06:58:54 +000075\setindexsubitem{(get method)}
Barry Warsaw17c8e781997-11-20 19:54:16 +000076
77\begin{funcdesc}{get}{}
78Gets and returns an item from the queue, blocking if necessary until
79one is available.
80\end{funcdesc}
81
Fred Drake19479911998-02-13 06:58:54 +000082\setindexsubitem{(get_nowait method)}
Barry Warsaw17c8e781997-11-20 19:54:16 +000083
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}