Reading lines from Python queues
<p>I'm dipping my toes into Python threading.  I've created a supplier thread that returns me character/line data from a *nix (serial) /dev via a Queue.</p>

<p>As an exercise, I would like to consume the data from the queue one line at a time (using '\n' as the line terminator).</p>

<p>My current (simplistic) solution is to put() only 1 character at a time into the queue, so the consumer will only get() one character at a time. (Is this a safe assumption?)  This approach currently allows me to do the following:</p>

<pre><code>...
return_buffer = []
while True:
    rcv_data = queue.get(block=True)
    return_buffer.append(rcv_data)        
    if rcv_data == "\n":
        return return_buffer
</code></pre>

<p>This seems to be working, but I can definitely cause it to fail when I put() 2 characters at a time.</p>

<p>I would like to make the receive logic more generic and able to handle multi-character put()s.</p>

<p>My next approach would be to rcv_data.partition("\n"), putting the "remainder" in yet another buffer/list, but that will require juggling the temporary buffer alongside the queue.
(I guess another approach would be to only put() one line at a time, but where's the fun in that?)</p>

<p>Is there a more elegant way to read from a queue one line at a time?</p>
