Python sleep doesn't work right in a loop?

2005-04-06 Thread ritterhaus
Just a simple bit of code to toggle between two state at intervals...

import time
for i in range(4):
print 'On'
time.sleep(1)
print 'Off'
time.sleep(1)

... SHOULD toggle On and Off four times with one-second pauses. When I
run this, the loop pauses the full eight seconds then prints the Ons
and Offs all at once. What's up with that?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python sleep doesn't work right in a loop?

2005-04-06 Thread ritterhaus
This is running in the interactive 'PyShell', but in truth those print
statements are part of a gui app that flashes a control in wx.widgets
by toggling it's background color. The same behavior either way.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python sleep doesn't work right in a loop?

2005-04-06 Thread ritterhaus
Nope. Does't work. Running Python 2.3.4 on Debian, Linux kernel 2.6.
This is actually test code for a larger project...

# 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.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python sleep doesn't work right in a loop?

2005-04-06 Thread ritterhaus
Actually, I've tried ALL of these things, and none of them work. I HAVE
run the simple for-print-sleep test code to try to determine if this
issue was specific to wx (that's good troubleshooting, folks - you
narrow down the problem) and even that didn't work, so I thought I'd
start with the simple problem first. Sorry if you were mislead.

As for wx, I HAVE used the for-setColour-refresh-update-sleep loop,
still no dice. The last thing the I put in the loop works (again, as if
all the changes are being queued) but the sleep just 'takes over' the
loop and nothing happens until al the sleeps are done. With or without
wx. Not good.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python sleep doesn't work right in a loop?

2005-04-07 Thread ritterhaus
I appreciate all the responses. It IS possible that wx and/or python is
whacked on my machine. I've got python 2.2 and 2.3 installed, I have
installed and uninstalled 2.4, I've had about three versions of wx
installed along the way for different programs, so it is possible that
it is just my machine.

Nevertheless, I came here looking for ideas, and you've given me some
good ones: some I had already tried (but I like validation) and some
were new to me. Thanks, all.

-- 
http://mail.python.org/mailman/listinfo/python-list