Is there a way to protect a piece of critical code?

Paul Rubin http
Thu Jan 11 01:31:39 EST 2007


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.



More information about the Python-list mailing list