"Paul Rubin" <http://[EMAIL PROTECTED]> wrote:
> "Hendrik van Rooyen" <[EMAIL PROTECTED]> writes: > > am aware of Queue module - the same app uses it for something else. > > I dont like too many try -- excepts in the code - I find they confuse > > me when I try to read it later - and in this case I cannot block on waiting for > > the queue to fill. > > Do you have multiple threads reading from the same queue? If not then > you can use queue.empty() to see whether the queue is empty. If yes, > queue.empty isn't reliable (it can return nonempty, and then another > thread empties out the queue before you get a chance to read it). But > you could always wrap the queue: > > QUEUE_IS_EMPTY = object() # global sentinel > > def get_from_queue(queue): > try: > return queue.get(block=False) > except Queue.Empty: > return QUEUE_IS_EMPTY > > Maybe it's worth adding a method like that to the Queue module in the stdlib. > There is only one reader. I like this its clever, thanks - Hendrik -- http://mail.python.org/mailman/listinfo/python-list