wxPython fast and slow

David Bolen db3l.net at gmail.com
Sun Mar 8 22:18:35 EDT 2009


iu2 <israelu at elbit.co.il> writes:

> Indeed, but I don't think the CallAfter is necessary. I could just as
> well remove the time.sleep in the original code. I could also make a
> tight loop to replace time.sleep
> for i in range(1000000): pass
> and tune it to fit the speed I need.

Except that CallAfter passed control back through the event loop which is
crucial for your GUI to appear responsive in other ways.

> I haven't mention this, but I actually want something to be the same
> speed on different PC-s. So a timer seems to fit in.

Then even a time.sleep() or plain loop isn't sufficient since each may
have additional latencies depending on load.  You will probably need
to query a system clock of some type to verify when your interval has
passed.

> I just can't make it work.
> Using wx.Timer is too slow.
> Using time.sleep is fast with PyScripter active, and slow when it is
> closed.

I have to admit to thinking that perhaps you're trying to operate too
quickly if you need better resolution than wx.Timer.  Most screen
operations don't have to appear that frequently to still appear
smooth, but that's your call.

Of course, even wx.Timer may be subject to other latencies if the
system or your application is busy with other events, so it depends
on how critical precise your timing needs to be.

You might also try an idle event, implementing your own timer (using
whatever call gives you the best resolution on your platform), and
just ignoring idle events that occur more frequently than the timing
you want.  Just remember to always request a new event.  You could do
the same thing with CallAfter as well, just reschedule a new one if
the current one is faster than your preferred interval.

-- David




More information about the Python-list mailing list