threads and exception in wxPython

Jeff Shannon jeff at ccvcorp.com
Wed Nov 3 20:38:41 EST 2004


Josiah Carlson wrote:

>Jeff Shannon <jeff at ccvcorp.com> wrote:
>  
>
>>Another possibility is to check the queue in an idle-event handler.  
>>When you place something in the queue, you can call wx.WakeUpIdle() to 
>>ensure that the main thread will do idle processing at its soonest 
>>opportunity.
>>    
>>
>
>The only ugly part about idle handling is that idle handlers are called
>quite often (at least in the wxPython versions I've run).  Specifically,
>whenever I move my mouse over a wxPython app window, idle events are
>streamed to the idle event handler at 30-60 events/second.
>
>Not really a big deal, but something people should know about none the
>less.
>  
>

True enough.  I believe that in most cases, checking a queue for content 
and acting if there's something there should be a fairly negligible 
load, and that typically it's a load that happens only when nothing else 
would be happening anyhow.  But it *is* something to be aware of, and 
one should be at least somewhat cautious about what's done during idle 
processing.  OTOH, it's a bit simpler to implement than creating a 
custom event and installing a handler for that... Not *much* simpler, as 
creating a custom event isn't exactly difficult, but in simple 
circumstances it has its benefits...  :)

(For those unfamiliar with wxPython's/wxWidgets' idle processing -- idle 
events are triggered every time an application's event queue *becomes* 
empty.  This means that if you get a few mouse events, and process them, 
then get a few more and process them... you get an idle event in between 
each batch of mouse events, and possibly between each individual mouse 
event depending on how fast your particular machine processes them.  But 
every time you get an idle event, it's because your app has nothing else 
to deal with at that moment in time.  It also means that if your window 
is in the background and not getting any new events in the queue, the 
queue will never switch from full to empty, and you won't get any idle 
events.  That's what wx.WakeUpIdle() is for -- to simulate the queue 
emptying and thus triggering an idle event.)

Jeff Shannon
Technician/Programmer
Credit International




More information about the Python-list mailing list