0

I have a python GUI that receives data from a C++ application via sockets, and updates its fields (Qt grid objects) and a 3D model in a Qthread. Updating the fields works properly in the thread, but I get a "Fatal Python error: GC object already tracked" when I add a function to update the 3D model (using the values in the updated fields) into the thread. The code runs for a few milliseconds but then crashes with the error. The 3D model creation and transformation is based on the Mayavi.mlab package.

I also tried putting the update 3D model function in another thread, but this didn't get rid of the error. Why might this error be occurring/how can I get rid of it?

Main Code:

    self.PSRThread = 0      # thread for the PSR server communication

    self.PSRUpdateThread = QtCore.QThread() # thread for updating the PSR fields
    self.PSRUpdateThread.start()
    self.PSRComm = 0

def InitPSRComm(self):      # activates on button click
            if (self.PSRThread == 0):
                self.PSRThread = ServerPSR.StartThread()                   
                self.PSRComm = UpdatePSRFields.PSRFieldUpdater( self.UpdateJointFields, self.PSRThread.receiveJointData,
                                    self.PSRThread.sendJointData, self.MovePSRModel, self.GetJoints,
                                    self.PSRTargetJointFields )
                self.PSRComm.sending = True
                self.PSRComm.moveToThread(self.PSRUpdateThread)
                self.PSRComm.start.emit("Start")
                print "Update PSR Fields thread started"

            if (self.PSRComm.sending == False):
                    self.PSRComm.sending = True

Thread Code:

class PSRFieldUpdater(QtCore.QObject):

start = QtCore.Signal(str)

def __init__(self, UpdateFieldsFunc, PSRThreadRecvFunc, PSRThreadSendFunc, UpdatePSRModelFunc, GetJointsFunc,
             *args):
    super(PSRFieldUpdater, self).__init__()

    self.UpdateFieldsFunc = UpdateFieldsFunc
    self.PSRThreadRecvFunc = PSRThreadRecvFunc
    self.PSRThreadSendFunc = PSRThreadSendFunc
    self.UpdatePSRModelFunc = UpdatePSRModelFunc
    self.GetJointsFunc = GetJointsFunc
    self.args = args
    self.start.connect(self.run)
    self.sending = False

def run(self):
    while (True):
        #print "sending status is: ", self.sending
        if (self.sending):
            PSRjoints = self.GetJointsFunc(*self.args)
            self.PSRThreadSendFunc(PSRjoints)
            #print "PSRThreadSendFunc called"
            self.sending = False
        j = self.PSRThreadRecvFunc()
        self.UpdateFieldsFunc(j)
        print "PSR fields updated"
        self.UpdatePSRModelFunc()

MovePSRModel():

def MovePSRModel(self):
            PSRjoints = self.GetJoints(self.PSRJointFields)
            j = transformPSR.PSRJoints(PSRjoints, partsList)
            j.MovePSR(PSRjoints, partsList)

If any other information is needed please let me know.

akivjh
  • 19
  • 6

1 Answers1

0

So it turns out that strange things happen with Qt GUi when you try and use threads within the main thread (I found this link to be relevant). I implemented things in the main GUI thread and used signals to communicate with it to do the updating.

Community
  • 1
  • 1
akivjh
  • 19
  • 6