Python sleep doesn't work right in a loop?

Diez B. Roggisch deetsNOSPAM at web.de
Wed Apr 6 16:20:20 EDT 2005


> Nope. Does't work. Running Python 2.3.4 on Debian, Linux kernel 2.6.
> This is actually test code for a larger project...

No Nope - it _does_ work. Did you actually try it? Because you use it in a
wrong context does not mean that it doesn't work. Besides, giving a wrong
example to prove a point is always a bad idea. 

> # flash the selected wx.TextControl
> 
> for flasher in range(4):
>     self.textField.SetBackgroundColour(255, 0, 0)
>     time.sleep(0.8)
>     self.textField.SetBackgroundColour(255, 255, 223)
>     time.sleep(0.8)
> 
> Even when I add an explicit call to repaint the TextCtrl between each
> sleep, things appear to be 'queued' until after the loop is fnished.
> Very bizarre.

That's a totally different thing - no idea how wx works in detail, but the
behaviour you describe looks as if the calls to SetBackgroundColour are
queued until the event loop is processed again. So check how to do that
manually between calls, and things are most probably working.

Again - giving the above example would made us give you that advice way
earlier - and saved us digging in the wrong direction...

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list