WX CallLater loop fails eventually

I wrote a small app which uses wx.CallLater to repeatedly update a ListCtrl with information. This happens every second.

If I leave the Suppress Asserts line commented out, it throws a “bogus timer id in wxTimerProc” AssertionError on the fourth run through the loop. Always the fourth.

If I Suppress the Asserts, it will run fine for a few hours before unexpectedly stopping its loop. The GUI thread is still active, though. I know that because I bound onClose to do some cleanup and that executes properly.

Any ideas?

Sample code:

import wx

class Monitor(wx.Frame):

def init(self,parent,title):

wx.Frame.init(self, parent, title=title)

self.count = 0

self.sizer = wx.BoxSizer(wx.VERTICAL)

self.outputListCtrl = wx.ListCtrl(self,style=wx.LC_REPORT|wx.BORDER_SUNKEN)

self.outputListCtrl.InsertColumn(0,‘Time’)

self.sizer.Add(self.outputListCtrl,1,wx.EXPAND|wx.ALL)

self.SetSizer(self.sizer)

self.SetAutoLayout(1)

self.sizer.Fit(self)

self.Show()

self.update()

def update(self):

print self.count

wx.CallLater(1000, self.update)

print self.count

self.outputListCtrl.DeleteAllItems()

self.outputListCtrl.InsertStringItem(0,’{}’.format(self.count))

self.count = self.count + 1

if name == ‘main’:

app = wx.App(False)

#app.SetAssertMode(wx.PYAPP_ASSERT_SUPPRESS)

frame = Monitor(None,‘Monitor’)

app.MainLoop()

Brian McFarland wrote:

I wrote a small app which uses wx.CallLater to repeatedly update a
ListCtrl with information. This happens every second.

Why not just use a wx.Timer? wx.CallLater has to create a timer on the
fly, and I suppose there may be an issue with creating a new timer while
you are in the handler for another timer.

If I leave the Suppress Asserts line commented out, it throws a "bogus
timer id in wxTimerProc" AssertionError on the fourth run through the
loop. Always the fourth.

If I Suppress the Asserts, it will run fine for a few hours before
unexpectedly stopping its loop. The GUI thread is still active,
though. I know that because I bound onClose to do some cleanup and
that executes properly.

Interesting. Which operating system? I don't see your "fourth time"
problem in Windows 7. I didn't have the patience to run several hours...

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.