我记得在某个地方看过一篇关于能够在主线程中从python中获取绘图的帖子,但我似乎无法找到它。我的第一次尝试是这样的,但它不起作用。它最初不会崩溃(最终会崩溃),但不会发生绘图。我的想法是options
是绘图函数的映射,每个函数都绘制到pyqtgraph或QTWidget等等。
from threading import *
from Queue import *
anObject1 = DrawingObject()
anObject2 = DrawingObject()
anObject3 = DrawingObject()
options = {
0 : anObject1.drawing_func,
1 : anObject2.drawing_func,
2 : anObject3.drawing_func,
3 : updateNon,
}
def do_work(item): #item is a tuple with the item at 0 is the index to which function
#print str(item) + "\n"
options[item[0]](item)
def worker():
while True:
item = q.get()
do_work(item)
q.task_done()
q = Queue()
#This function is a callback from C++
def callback(s, tuple):
#options[tuple[0]](tuple) #this works
q.put(tuple) #this does not
num_worker_threads = 3
for i in range(num_worker_threads):
t = Thread(target=worker)
t.daemon = True
t.start()