1 \section{\module{Queue
} ---
2 A synchronized queue class.
}
3 \declaremodule{standard
}{Queue
}
5 \modulesynopsis{A synchronized queue class.
}
9 The
\module{Queue
} module implements a multi-producer, multi-consumer
10 FIFO queue. It is especially useful in threads programming when
11 information must be exchanged safely between multiple threads. The
12 \class{Queue
} class in this module implements all the required locking
13 semantics. It depends on the availability of thread support in
16 The
\module{Queue
} module defines the following class and exception:
19 \begin{classdesc
}{Queue
}{maxsize
}
20 Constructor for the class.
\var{maxsize
} is an integer that sets the
21 upperbound limit on the number of items that can be placed in the
22 queue. Insertion will block once this size has been reached, until
23 queue items are consumed. If
\var{maxsize
} is less than or equal to
24 zero, the queue size is infinite.
27 \begin{excdesc
}{Empty
}
28 Exception raised when non-blocking
\method{get()
} (or
29 \method{get_nowait()
}) is called on a
\class{Queue
} object which is
34 Exception raised when non-blocking
\method{put()
} (or
35 \method{get_nowait()
}) is called on a
\class{Queue
} object which is
39 \subsection{Queue Objects
}
42 Class
\class{Queue
} implements queue objects and has the methods
43 described below. This class can be derived from in order to implement
44 other queue organizations (e.g. stack) but the inheritable interface
45 is not described here. See the source code for details. The public
48 \begin{methoddesc
}{qsize
}{}
49 Return the approximate size of the queue. Because of multithreading
50 semantics, this number is not reliable.
53 \begin{methoddesc
}{empty
}{}
54 Return
\code{1} if the queue is empty,
\code{0} otherwise. Because
55 of multithreading semantics, this is not reliable.
58 \begin{methoddesc
}{full
}{}
59 Return
\code{1} if the queue is full,
\code{0} otherwise. Because of
60 multithreading semantics, this is not reliable.
63 \begin{methoddesc
}{put
}{item
\optional{, block
}}
64 Put
\var{item
} into the queue. If optional argument
\var{block
} is
1
65 (the default), block if necessary until a free slot is available.
66 Otherwise (
\var{block
} is
0), put
\var{item
} on the queue if a free
67 slot is immediately available, else raise the
\exception{Full
}
71 \begin{methoddesc
}{put_nowait
}{item
}
72 Equivalent to
\code{put(
\var{item
},
0)
}.
75 \begin{methoddesc
}{get
}{\optional{block
}}
76 Remove and return an item from the queue. If optional argument
77 \var{block
} is
1 (the default), block if necessary until an item is
78 available. Otherwise (
\var{block
} is
0), return an item if one is
79 immediately available, else raise the
80 \exception{Empty
} exception.
83 \begin{methoddesc
}{get_nowait
}{}
84 Equivalent to
\code{get(
0)
}.