【问题标题】:wxpython threading a task and update the GUI causeswxpython 线程化任务并更新 GUI 原因
【发布时间】:2012-12-12 00:08:12
【问题描述】:

我有一些简单的 wxpython GUI,当我单击按钮时,我想在另一个线程中运行一些 io 任务(为了不阻塞 GUI)并在 io 线程运行时相应地更新 GUI(例如从 io 线程将标签更新为:"[io task percent completed]%")。

但有时这可行,但有时会引发异常:

The program 'python2.7' received an X Window System error.
This probably reflects a bug in the program.
The error was 'RenderBadPicture (invalid Picture parameter)'.
  (Details: serial 14127 error_code 163 request_code 149 minor_code 7)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)

使用 --sync 命令运行程序会产生以下错误:

[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called

我读到不允许从创建 GUI 的线程之外的另一个线程更新 GUI 线程,但如果是这种情况,如何完成这个简单的任务?从另一个线程更新 GUI。

谢谢

【问题讨论】:

    标签: multithreading wxpython


    【解决方案1】:

    这里已经有很多关于这个主题的主题,并且在 wxpython wiki 上得到了很好的介绍。查找 wx.CallAfter。

    【讨论】:

    • 谷歌搜索 wxpython wiki 给出了结果,谢谢 :) 但是你知道一些使用队列和计时器的来源吗?我想和他们验证我的推理。
    猜你喜欢
    • 2023-04-04
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    相关资源
    最近更新 更多