python - How can I acquire data from live experimentation and do a live 2D plot using threads? -


i need take data instrument , live 2d plot them. can without threads, slow ... how proceed without having errors "qobject::setparent: cannot set parent, new parent in different thread", "qapplication: object event filter cannot in different thread" , "qpixmap: not safe use pixmaps outside gui thread". used code test:

    import threading     import time     import numpy np     import matplotlib.pyplot plt     class mythread (threading.thread):       def __init__(self, threadid, name, counter):       threading.thread.__init__(self)       self.threadid = threadid       self.name = name       self.counter = counter       s=(6,6)        self.x=np.zeros(s)       def run(self):          print "starting " + self.name          threadlock.acquire()           if self.threadid==1:            acquire_data(self.x)            count_to_three(self.name,1)            plot_it(self.x)            count_to_three(self.name,1)            print "exiting "+ self.name           if self.threadid==2:             count_to_three(self.name,1)             print "exiting "+ self.name           threadlock.release()    def print_time(threadname, delay, counter):     while counter:     time.sleep(delay)     print "%s: %s" % (threadname, time.ctime(time.time()))     counter -= 1 def count_to_three(threadname,delay):    i=0    while i<4:        time.sleep(delay)        print"%s: %s" % (threadname,i)        i+=1  def acquire_data(x):     return  def plot_it(x):   sidex = np.linspace(0,6,6)    sidey = np.linspace(0,6,6)   x,y = np.meshgrid(sidex,sidey)   plt.subplot(111)   plt.pcolormesh(x,y,x)    return   # create new threads     plt.figure()   threadlock=threading.lock()   while true:       threads=[]      thread1 = mythread(1, "thread-1", 3)      thread2 = mythread(2, "thread-2", 2)      # start new threads      thread1.start()      thread2.start()     # add threads thread list    threads.append(thread1)    threads.append(thread2)     t in threads:       plt.show()       t.join() 


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -