Oops -- Lib/Test should be Lib/test, of course!
[python/dscho.git] / Doc / lib / libqueue.tex
blob680238d78a61cbe2d75d98955dc28ca26fcb39c8
1 \section{Standard Module \module{Queue}}
2 \stmodindex{Queue}
3 \label{module-Queue}
6 The \module{Queue} module implements a multi-producer, multi-consumer
7 FIFO queue. It is especially useful in threads programming when
8 information must be exchanged safely between multiple threads. The
9 \class{Queue} class in this module implements all the required locking
10 semantics. It depends on the availability of thread support in
11 Python.
13 The \module{Queue} module defines the following class and exception:
16 \begin{classdesc}{Queue}{maxsize}
17 Constructor for the class. \var{maxsize} is an integer that sets the
18 upperbound limit on the number of items that can be placed in the
19 queue. Insertion will block once this size has been reached, until
20 queue items are consumed. If \var{maxsize} is less than or equal to
21 zero, the queue size is infinite.
22 \end{classdesc}
24 \begin{excdesc}{Empty}
25 Exception raised when non-blocking get (e.g. \method{get_nowait()}) is
26 called on a \class{Queue} object which is empty, or for which the
27 emptyiness cannot be determined (i.e. because the appropriate locks
28 cannot be acquired).
29 \end{excdesc}
31 \subsection{Queue Objects}
32 \label{QueueObjects}
34 Class \class{Queue} implements queue objects and has the methods
35 described below. This class can be derived from in order to implement
36 other queue organizations (e.g. stack) but the inheritable interface
37 is not described here. See the source code for details. The public
38 methods are:
40 \begin{methoddesc}{qsize}{}
41 Returns the approximate size of the queue. Because of multithreading
42 semantics, this number is not reliable.
43 \end{methoddesc}
45 \begin{methoddesc}{empty}{}
46 Returns \code{1} if the queue is empty, \code{0} otherwise. Because
47 of multithreading semantics, this is not reliable.
48 \end{methoddesc}
50 \begin{methoddesc}{full}{}
51 Returns \code{1} if the queue is full, \code{0} otherwise. Because of
52 multithreading semantics, this is not reliable.
53 \end{methoddesc}
55 \begin{methoddesc}{put}{item}
56 Puts \var{item} into the queue.
57 \end{methoddesc}
59 \begin{methoddesc}{get}{}
60 Gets and returns an item from the queue, blocking if necessary until
61 one is available.
62 \end{methoddesc}
64 \begin{methoddesc}{get_nowait}{}
65 Gets and returns an item from the queue if one is immediately
66 available. Raises an \exception{Empty} exception if the queue is
67 empty or if the queue's emptiness cannot be determined.
68 \end{methoddesc}