Python:无阻塞队列

Python:无阻塞队列,python,multithreading,wxpython,Python,Multithreading,Wxpython,我有一个关于排队的问题。我正在用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, pa

我有一个关于排队的问题。我正在用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
但现在的问题是,程序仍然会阻塞,我认为这是因为队列正在等待一个项目。我可以在一个新线程中启动它,但是我必须再次处理队列,以便在我的主线程中执行该函数。 有人能帮我吗? 提前谢谢。

我建议您使用。你可以找到一些有用的例子。您还可以使用模块向GUI发送消息。这样您的GUI就不会因为其他线程而阻塞

这是一个很好的博客,当我有一个类似的问题时,我读了你的。 您还可以在SO上找到一些其他问题,这些问题可能有助于您理解这个概念