I use the COMMAND_TIMEOUT's default of 10s when querying the queue for data.  When we get a stop message (ie, item is 0) there's a race condition where the queue might contain either ('last element', 0) or (0, 'last element').  This code handles getting that last bit of data out.  We've gotten the signal that there's no more data coming, so just clear out what's in the queue, and do it quickly.