When several producer threads put items in a queue.Queue, and a consumer thread gets items from the queue, there is no way for the consumer thread to tell the producers that they should stop feeding the queue. This snippet defines a subclass of Queue with a close method. After the queue has been closed, producer threads which attempt to put items in the queue will receive a Closed exception.
Priority queues and lifo queues are provided as well.
This code has been tested with python 2.6 and 3.1.