Thread limits?

Tim Peters tim_one at email.msn.com
Sun Aug 20 23:54:13 EDT 2000


[Tim]
>> ... that the queue is empty merely means that all requests have
>> been removed from it, not that even a single one of them has
>> been *acted* upon yet.

[François Pinard]
> If the queue behaves like a FIFO (which you confirmed in your reply)
> and is empty, I would think it is reliable to say that all real
> requests have been processed.

Yes -- although, as the docs say, Queue.qsize() is not reliable!  There's
simply no way to tell whether a Queue object is empty short of building
another protocol on top of it.

> Each thread did receive a termination request if the queue is empty,
> and either has terminated, or is busy terminating itself.

I don't know why you're so keen to avoid the thread.join() loop, which is
*obviously* reliable.  If the main thread goes away, and you haven't used
the threading module, then depending on the OS and the platform threading
package, the child threads may or may not get killed in mid-stream (indeed
yes *while* they're "busy terminating themselves").  So it's simply good
practice to wait for the threads to clean up after themselves first, and an
explicit .join loop is the obvious way to do that.

>> The Queue class is "sequentially consistent" from the point of view of
>> any single thread.  To make that concrete, if thread T queues X
>> and later (the same thread T!) queues Y, X *will* be removed from
>> the queue before Y is.

> Excellent.  Could the above sentence be added to the documentation?  So,
> we could more definitely rely on it, and there would be no place for
> confusion.

I leave that decision to Fred Drake, who I've copied on this.  The docs
already say it's a FIFO, and I think you're looking for more words only
because a half-remembered thread from the dim past spread half-remembered
false rumors <wink -- but I barely remember that thread now too, and it
"smelled like" a platform-specific threading bug>.  Since anyone reading the
docs without that background would read "FIFO" and *think* "FIFO", I believe
the docs give an accurate story already.






More information about the Python-list mailing list