Unexpected Behavior When Appending Multiple List Inside function in PyQt GUI
<p>I am experiencing strange behavior while trying to append to two different lists from inside of the same function. </p>

<pre><code>x = 0
y = 0
list_1 = []
list_2 = []

def append_function(self):
    self.x += 1
    self.y += 1
    self.list_1.append(self.x)
    self.list_2.append(self.y)        
    print self.list_1
    print self.list_2
</code></pre>

<p>The output that I would expect from running the function once is:</p>

<pre><code>[1]
[1]
</code></pre>

<p>If I ran twice I would expect:</p>

<pre><code>[1,2]
[1,2]
</code></pre>

<p>The actual output that I get from running the function once is:</p>

<blockquote>
  <p>[1]</p>
</blockquote>

<p>When I run the function twice I get:</p>

<pre><code>[1]
[1,2]
</code></pre>

<p>Every time I run the function the first list lags behind. This only happens when I run the code inside of the GUI class. Otherwise it runs as expected. Does anyone know why this happens or know a workaround?</p>

<p>Here's the entire program:</p>

<pre><code>#imports
from PyQt4 import QtGui
from PyQt4 import QtCore

import ui_sof_test  #Gui File
import sys

class Worker(QtCore.QThread):


    def run(self):                
        pass
class Gui(QtGui.QMainWindow, ui_sof_test.Ui_MainWindow):

    def __init__(self):        
        super(self.__class__, self).__init__()        
        self.setupUi(self)  
        self.start()
        self.pushButton.clicked.connect(self.append_function)
    x = 0
    y = 0
    list_1 = []
    list_2 = []

    def append_function(self):
        self.x += 1
        self.y += 1
        self.list_1.append(self.x)
        self.list_2.append(self.y)        
        print self.list_1
        print self.list_2

    #------------------------------------------------------------------------------------------------#
    #                                        Worker Thread(s) Setup                                  #
    ##################################################################################################

    def start(self):  
        self.setupWorker()


    def setupWorker(self):
        self.work = Worker()
        #self.work.mcx.connect(self.setxy,QtCore.Qt.QueuedConnection)
        #self.work.mcy.connect(self.move_cur_lifty,QtCore.Qt.QueuedConnection)
        if not self.work.isRunning():#if the thread has not been started let's kick it off
            self.work.start()

def main():
    app = QtGui.QApplication(sys.argv)  # A new instance of QApplication
    form = Gui()  # We set the form to be our ExampleApp (design)
    form.show()  # Show the form
    app.exec_()  # and execute the. app

if __name__ == '__main__':  # if we're running file directly and not importing it
    main()  # run the main function
</code></pre>

<p>The problem is unique to the Iron Python console in the Spyder IDE. Running the code in another python terminal produces the expected result.</p>

python python-2.7 pyqt4