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
15 The
\module{Queue
} module defines the following class and exception:
18 \begin{classdesc
}{Queue
}{maxsize
}
19 Constructor for the class.
\var{maxsize
} is an integer that sets the
20 upperbound limit on the number of items that can be placed in the
21 queue. Insertion will block once this size has been reached, until
22 queue items are consumed. If
\var{maxsize
} is less than or equal to
23 zero, the queue size is infinite.
26 \begin{excdesc
}{Empty
}
27 Exception raised when non-blocking
\method{get()
} (or
28 \method{get_nowait()
}) is called on a
\class{Queue
} object which is
33 Exception raised when non-blocking
\method{put()
} (or
34 \method{put_nowait()
}) is called on a
\class{Queue
} object which is
38 \subsection{Queue Objects
}
41 Class
\class{Queue
} implements queue objects and has the methods
42 described below. This class can be derived from in order to implement
43 other queue organizations (e.g. stack) but the inheritable interface
44 is not described here. See the source code for details. The public
47 \begin{methoddesc
}{qsize
}{}
48 Return the approximate size of the queue. Because of multithreading
49 semantics, this number is not reliable.
52 \begin{methoddesc
}{empty
}{}
53 Return
\code{1} if the queue is empty,
\code{0} otherwise. Because
54 of multithreading semantics, this is not reliable.
57 \begin{methoddesc
}{full
}{}
58 Return
\code{1} if the queue is full,
\code{0} otherwise. Because of
59 multithreading semantics, this is not reliable.
62 \begin{methoddesc
}{put
}{item
\optional{, block
}}
63 Put
\var{item
} into the queue. If optional argument
\var{block
} is
1
64 (the default), block if necessary until a free slot is available.
65 Otherwise (
\var{block
} is
0), put
\var{item
} on the queue if a free
66 slot is immediately available, else raise the
\exception{Full
}
70 \begin{methoddesc
}{put_nowait
}{item
}
71 Equivalent to
\code{put(
\var{item
},
0)
}.
74 \begin{methoddesc
}{get
}{\optional{block
}}
75 Remove and return an item from the queue. If optional argument
76 \var{block
} is
1 (the default), block if necessary until an item is
77 available. Otherwise (
\var{block
} is
0), return an item if one is
78 immediately available, else raise the
79 \exception{Empty
} exception.
82 \begin{methoddesc
}{get_nowait
}{}
83 Equivalent to
\code{get(
0)
}.