wxTimer never times out sometimes

Jeffrey Barish jeff_barish at earthlink.net
Thu Aug 17 13:19:55 PDT 2006


Josiah Carlson wrote:

> 
> Jeffrey Barish <jeff_barish at earthlink.net> wrote:
>> 
>> I use the timer in one-shot mode to trigger an action after the user
>> stops
>> using the GUI.  As long as the user is clicking on elements in the GUI,
>> the
>> timer gets retriggered (using Start).  This scheme works fine most of the
>> time, but once in a while the event handler never gets called.  After the
>> timer fails once, it seems to be inoperable.  That is, I don't get a
>> timeout after performing additional actions that normally would trigger
>> the
>> timer.  The only way to restore correct operation is to exit the program
>> and restart it.  My only theory is that something goes wrong if wxTimer
>> receives a start command at the same time that it is timing out.  That is
>> the only scenario I can think of consistent with the sporadic nature of
>> the
>> problem.  Perhaps there needs to be a critical section in the code.
> 
> If you are using wxTimer.Start() in a thread other than the main thread,
> then you need to change your code, as such is not supported on any
> platform (regardless of whether it works or not on your platform).  That
> is, post an event to the GUI thread, that event's only job is triggering
> the wxTimer.Start().
> 
> If the only thread that is executing is your single main thread, then I
> doubt you are running into a race condition that requires a critical
> section or lock (either in the underlying wxPython implementation or in
> your code), but you may need to wait for a response from Robin to be
> sure.
> 
Thanks for your comments.  You raise a good point, but there is only one
thread.  I was thinking that the actions that result in calls to
wxTimer.Start() happen asynchronously to the timer.  Accordingly, it could
be possible that the timer is running code for dealing with actions the
timer takes at the end of the timer period at the moment it receives the
Start() call.  If so, perhaps it goes into a state in which it does not
transmit the timer event and does not properly reset the timer.  The
critical section would be the code that handles the timeout to be sure that
the timer does everything that needs to be done before it responds to the
new Start() call.  It's also possible that I am completely wrong, but I
have no other theory for explaining why I never get a timer event
sometimes.  I know that the timer was triggered because I display a static
bitmap at the same time.  When the timer times out, the static bitmap
should disappear and I should see a message indicating that I made it to
the timer event handler.  Neither thing happens.  Also, it is not possible
to trigger the timer again.
-- 
Jeffrey Barish





More information about the wxpython-users mailing list