python - 线程、wxpython 和状态栏

标签 python multithreading wxpython statusbar

我正在做一个使用 wxStatusBar 的程序,当下载开始时,我会像这样启动一个子线程:

def OnDownload(self, event):
    child = threading.Thread(target=self.Download)
    child.setDaemon(True)
    child.start()

下载是另一个没有参数的函数(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

最佳答案

大多数人被引导到 wxPython wiki:

http://wiki.wxpython.org/LongRunningTasks

我在这里也写了一篇关于这个主题的小文章:

http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/

不过,我认为我以前从未见过您的解决方案。

关于python - 线程、wxpython 和状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4692726/

相关文章:

python - wxpython createStatusBar 奇怪的行为

python - 使 wxPython TextCtrl 响应 cr 或 tab

python - Xvfbwrapper 模块返回异常

python - 如何在 Python 中使用多个键解析和排序 JSON

python - 使用 Headless Chrome Webdriver 运行 Selenium

c# - 访问 GUI 元素未按预期工作

python - self.Bind 上的 wxPython 方法 "takes 1 positional argument but 2 were given"

python - numpy C API 中的 import_array 如何工作?

java - 自定义模态对话框

java - 通知不唤醒等待线程