Is there a way to protect a piece of critical code?
Hendrik van Rooyen
mail at microcorp.co.za
Fri Jan 12 00:03:11 EST 2007
"Paul Rubin" <http://phr.cx@NOSPAM.invalid> wrote:
> Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> > def get_from_queue(queue):
> > try:
> > return queue.get(block=False)
> > except Queue.Empty:
> > return QUEUE_IS_EMPTY
>
> Alternatively:
>
> def get_from_queue(queue):
> try:
> return (queue.get(block=False), True)
> except Queue.Empty:
> return (None, False)
>
> This is maybe a nicer interface (no special sentinel value needed).
> You'd use
>
> value, nonempty = get_from_queue(queue)
>
> if nonempty is true then the item is valid.
>
Hey, this is even nicer - thanks!
- Hendrik
More information about the Python-list
mailing list