WX CallLater loop fails eventually

24 views
Skip to first unread message

Brian McFarland

unread,
May 22, 2015, 7:26:00 PM5/22/15
to wxpytho...@googlegroups.com
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()

Tim Roberts

unread,
May 22, 2015, 7:42:46 PM5/22/15
to wxpytho...@googlegroups.com
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, ti...@probo.com
Providenza & Boekelheide, Inc.

Reply all
Reply to author
Forward
0 new messages