Queue.Queue()

Tim Peters tim.peters at gmail.com
Fri Feb 17 12:09:48 EST 2006


[john peter]
>  what happens behind the scenes when i create a Queue.Queue() without
> specifying a maxsize?  does a block of space gets allocated initially then
> dynamically "expanded" as needed?

Yes.

> if so, what is the default size of the initial space?

It's initially empty.

> is it always better to specify a big enough maxsize

No.

> initially for efficiency purposes,

The intent has nothing to do with efficiency:  bounded and unbounded
queues are _semantic_ variations.  They can behave differently. 
Whether you want a bounded or unbounded queue depends on the needs of
your app.  A bounded queue is typically used, e.g., to mediate between
producers and consumers with different processing rates.

> or does it matter much?

Shouldn't matter at all.  Even if you specify a max size, the
underlying container still starts its life empty, and grows and
shrinks as needed.  The semantic difference is in whether a .put()
attempt may block.



More information about the Python-list mailing list