【发布时间】:2011-06-09 05:28:30
【问题描述】:
我正在做一个使用 wxStatusBar 的程序,当下载开始时,我会像这样启动一个子线程:
def OnDownload(self, event):
child = threading.Thread(target=self.Download)
child.setDaemon(True)
child.start()
Download 是另一个没有参数的函数(self 除外)。我想从那里用一些关于下载进度的信息来更新我的状态栏,但是当我尝试这样做时,我经常会遇到 Xwindow、glib 和 segfaults 错误。有什么办法解决这个问题吗?
已解决:我只需要在线程内更改 GUI 中的某些内容之前包含 wx.MutexGuiEnter() 并在完成后包含 wx.MutexGuiLeave()。例如
def Download(self):
#stuff that doesn't affect the GUI
wx.MutexGuiEnter()
self.SetStatusText("This is a thread")
wx.MutexGuiLeave()
仅此而已:D
【问题讨论】:
标签: python multithreading wxpython statusbar