user interface - Python crashing when updating wxPython GUI from thread -


i have searched extensively solution issue i'm having no avail. i'm writing program has wxpython html window contained inside normal window. when program starts, spawns several threads check new images on site, , if found should displayed in wxpython html window. i'm doing call function in gui class.

def appendpage(self, text):     self.freeze()     self.htmlwin.appendtopage(text)     self.thaw() 

(the text variable html code display scraped images)

this function called 1 of threads collects image file urls. have tried using wx.callafter method when calling appendpage function when calling appendtopage method. regardless, program stops , "python.exe has stopped working" appears. sorry if wasn't incredibly clear, didn't include sample code because program error coming quite large , using several outside libraries. i'm @ loss need in order allow threads update gui.

solution simple, don't use threads , graphical libraries intertwined..

your application crash no matter what, unless use threads gather data gui fetches thread.join() or similar, you're fine.
long try update any graphical element thread segfault application.

how graphical libraries work (why? don't know honest has locks, access memory between threads don't write stuff graphic card multiple sources @ once. 1 thing sure, it's because sheer complexity of rendering engine bugger understand , maintain.. , reward isn't great).

use select.epoll instead of threads gather data, won't need threads data won't lock application waiting data either.

this give idea of how turn problem around , instead of giving thread job call graphical change, change can reversed fetch data thread.

another way give thread local variable of mainwindow such self.data , update graphical element self.htmlwin.appendtopage(self.data) each render sequence.

class mainwindow():     def __init__(self):         self.thread = start_thread('http://google.com')     def appendpage(self, text):         self.freeze()         self.htmlwin.appendtopage(text)         self.thaw()     def run(self):         while self.alive:             self.append(self.thread.data)             self.render() 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -