2012-12-26 22 views
2

我有一些簡單的wxpython GUI,當我點擊一個按鈕時,我想在另一個線程中運行一些io任務(爲了不阻止GUI)並更新GUI在io線程正在運行時(例如,將標籤更新爲:[io task percentage completed%])。wxpython線程化任務並更新GUI原因

但是有時候這工作,有時拋出一個異常:

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。

感謝

回答

0

已經有噸對這個話題的線索在這裏,而且它很好地覆蓋在wxPython的維基。查找wx.CallAfter。

+0

谷歌搜索wxpython維基給出了結果,謝謝:)但是,你知道一些使用隊列和定時器的源?我想驗證我的推理與他們。 –