Queue- Multi Threading Python
<p>I have a bunch of code and I am attaching a piece here. Basically I have a thread - which is targeted on a function - that has a while loop as following :</p>

<pre><code>while not stop_event.wait(1): # Continuous Reading Function

    #print "hello2"
    #print ("working on %s" % arg)
    data1 = Read(soa1, bytes1, ser)
    data2 = Read(soa2, bytes2, ser)
    data3 = Read(soa3, bytes3, ser)

    data = np.concatenate([data1, data2, data3])
    print data.size
    queue_read.put(data)
    time.sleep(1)
</code></pre>

<p>I am reading the data from an MCU, through serial communication in this thread and sending it back to my Main program - using queue_read.put(data). This while is ran every 1 second.</p>

<p>In my main program I am reading the output from this thread as ---</p>

<pre><code>self.data = queue_read.get()
</code></pre>

<p>After five minutes the values in the MCU are intentionally changed. During the change this thread is still running as it is in while loop.</p>

<p>So after five minutes, the variable "data" should have the updated new values from the MCU. But to my surprise it does not. It still has the initial values. Is there anything I am missing here? Is using queue, the right way to get data?</p>

<p>The following approach reads and processes data from the queue continuously, which allows you to see and respond to data changes as they happen:</p>

<pre><code>while True:
    self.data = queue_read.get()
    self.update_GUI() 
</code></pre>

<p><code>queue_read.get()</code> blocks if <code>queue_read</code> is empty. You will need to run this code in its own thread if the main thread does anything other than update the GUI.</p>

python multithreading variables queue pyserial