python - Multiple wx.Yield() alternative -


i have wxpython gui application reads growing text file , prints wx.textctrl window. need have 2 of these running @ same time, bumping wxyield called recursively error. there easy alternative wx.yield allow me run multiples please?

self.running_log = wx.textctrl(self, -1, pos=(5, 5), size=(875,605),                                        style = wx.te_multiline|wx.te_readonly|wx.hscroll)  while true:     wx.yield()     filesize = os.path.getsize(logpath)     if filesize > lastsize:         lines = infile.readlines()         newlines = 0         line in lines[lastlineindex:]:             newlines += 1             print line.rstrip()         self.running_log.appendtext(line) 

have @ wxpython wiki: longrunningtasks. there you'll see 2 alternatives using wxyield: threading or putting processing evt_idle handler.

but since you're using wxyield, let me suggest solution can try before changing else: use flag indicate whether running or not. if flag true, don't let code execute wxyield again.

when call wx.yield(), wxpython take control , process events needs take care of. when finished, long running task proceed again, right after yield call. can put processing in loop , let spin there long needs to. adding flag limit entry point yield is. when processing has finished release 'lock' toggling flag, , entry point of code changes actual method invocation again.

something along lines of:

if not running:     running = true     while true:         wx.yield()         filesize = os.path.getsize(self.logpath)         if filesize > lastsize:             lines = infile.readlines()             newlines = 0             line in lines[lastlineindex:]:                 newlines += 1                 self.running_log.appendtext(line)         # when finished, set running false , break 

note might idea check how getsize called. if happens limit ensuring short amount of time has elapsed, avoid excessive calls slowing down system.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -