【发布时间】:2015-07-02 09:52:42
【问题描述】:
我记得在某处看到一篇关于能够从主线程中获取 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()
【问题讨论】:
-
谢谢,不是它,但它确实看起来不错!
标签: python qt python-multithreading pyqtgraph