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
16 \seemodule{bisect
}{PriorityQueue example using the Queue class
}
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.
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
37 Exception raised when non-blocking
\method{put()
} (or
38 \method{put_nowait()
}) is called on a
\class{Queue
} object which is
42 \subsection{Queue Objects
}
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
51 \begin{methoddesc
}{qsize
}{}
52 Return the approximate size of the queue. Because of multithreading
53 semantics, this number is not reliable.
56 \begin{methoddesc
}{empty
}{}
57 Return
\code{True
} if the queue is empty,
\code{False
} otherwise.
58 Becauseof multithreading semantics, this is not reliable.
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.
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}
80 \begin{methoddesc
}{put_nowait
}{item
}
81 Equivalent to
\code{put(
\var{item
}, False)
}.
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}
98 \begin{methoddesc
}{get_nowait
}{}
99 Equivalent to
\code{get(False)
}.