【发布时间】:2014-05-02 09:37:58
【问题描述】:
我有一个关于队列的问题。我正在用 wxpython 创建一个 GUI,在程序中我需要在一个单独的线程中做一些事情。线程完成后,我必须修改 gui。 GUI 不应在其他线程运行时阻塞。 为此,我想到了队列并写了如下内容:
def do_something(gui):
# Here it normally does something
gui.queue.put(gui.new)
class GuiFrame(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, title="Test")
self.queue = Queue.Queue()
self.calculate()
def calculate(self):
thread = threading.Thread(target=do_something, args=(self,))
thread.start()
function = self.queue.get()
function()
def new():
# Here something modifies the gui
pass
但现在的问题是,程序仍然阻塞,我认为是因为队列正在等待一个项目。我可以在一个新线程中启动它,但是我必须再次对队列执行此操作,才能在我的主线程中执行该函数。 有谁能够帮助我? 提前谢谢你。
【问题讨论】:
标签: python multithreading wxpython