Move setting of ioready 'wait' earlier in call chain, to
[python/dscho.git] / Doc / lib / libqueue.tex
blob0770bfe8ab61096357e2c3c87be15c2051e4dd4e
1 \section{\module{Queue} ---
2 A synchronized queue class}
4 \declaremodule{standard}{Queue}
5 \modulesynopsis{A synchronized queue class.}
8 The \module{Queue} module implements a multi-producer, multi-consumer
9 FIFO queue. It is especially useful in threads programming when
10 information must be exchanged safely between multiple threads. The
11 \class{Queue} class in this module implements all the required locking
12 semantics. It depends on the availability of thread support in
13 Python.
15 \begin{seealso}
16 \seemodule{bisect}{PriorityQueue example using the Queue class}
17 \end{seealso}
19 The \module{Queue} module defines the following class and exception:
22 \begin{classdesc}{Queue}{maxsize}
23 Constructor for the class. \var{maxsize} is an integer that sets the
24 upperbound limit on the number of items that can be placed in the
25 queue. Insertion will block once this size has been reached, until
26 queue items are consumed. If \var{maxsize} is less than or equal to
27 zero, the queue size is infinite.
28 \end{classdesc}
30 \begin{excdesc}{Empty}
31 Exception raised when non-blocking \method{get()} (or
32 \method{get_nowait()}) is called on a \class{Queue} object which is
33 empty or locked.
34 \end{excdesc}
36 \begin{excdesc}{Full}
37 Exception raised when non-blocking \method{put()} (or
38 \method{put_nowait()}) is called on a \class{Queue} object which is
39 full or locked.
40 \end{excdesc}
42 \subsection{Queue Objects}
43 \label{QueueObjects}
45 Class \class{Queue} implements queue objects and has the methods
46 described below. This class can be derived from in order to implement
47 other queue organizations (e.g. stack) but the inheritable interface
48 is not described here. See the source code for details. The public
49 methods are:
51 \begin{methoddesc}{qsize}{}
52 Return the approximate size of the queue. Because of multithreading
53 semantics, this number is not reliable.
54 \end{methoddesc}
56 \begin{methoddesc}{empty}{}
57 Return \code{True} if the queue is empty, \code{False} otherwise.
58 Becauseof multithreading semantics, this is not reliable.
59 \end{methoddesc}
61 \begin{methoddesc}{full}{}
62 Return \code{True} if the queue is full, \code{False} otherwise.
63 Because of multithreading semantics, this is not reliable.
64 \end{methoddesc}
66 \begin{methoddesc}{put}{item\optional{, block\optional{, timeout}}}
67 Put \var{item} into the queue. If optional args \var{block} is true
68 and \var{timeout} is None (the default), block if necessary until a
69 free slot is available. If \var{timeout} is a positive number, it
70 blocks at most \var{timeout} seconds and raises the \exception{Full}
71 exception if no free slot was available within that time.
72 Otherwise (\var{block} is false), put an item on the queue if a free
73 slot is immediately available, else raise the \exception{Full}
74 exception (\var{timeout} is ignored in that case).
76 \versionadded[the timeout parameter]{2.3}
78 \end{methoddesc}
80 \begin{methoddesc}{put_nowait}{item}
81 Equivalent to \code{put(\var{item}, False)}.
82 \end{methoddesc}
84 \begin{methoddesc}{get}{\optional{block\optional{, timeout}}}
85 Remove and return an item from the queue. If optional args
86 \var{block} is true and \var{timeout} is None (the default),
87 block if necessary until an item is available. If \var{timeout} is
88 a positive number, it blocks at most \var{timeout} seconds and raises
89 the \exception{Empty} exception if no item was available within that
90 time. Otherwise (\var{block} is false), return an item if one is
91 immediately available, else raise the \exception{Empty} exception
92 (\var{timeout} is ignored in that case).
94 \versionadded[the timeout parameter]{2.3}
96 \end{methoddesc}
98 \begin{methoddesc}{get_nowait}{}
99 Equivalent to \code{get(False)}.
100 \end{methoddesc}