tags:

views:

85

answers:

1

I have the following code

print "Starting stage 1<br>"

# Something that takes about 5 seconds
time.sleep(5)

print "Stage 1 complete"

I view the script with my browser as it's part of a web-app, the problem is that it's displaying all of it together, I want it to display first the starting message before it starts and then add the completion message after it's complete.

What do I use to push information to the browser in this fashion?

+5  A: 

Try flush the output after the first print using sys.stdout.flush()

marcog
Awesome, that's working perfectly. Thanks :)
Teifion
Note that this only works so long as your web server isn't buffering output.
Evan Fosmark
Ahh, that's a useful tidbit to know, cheers.
Teifion
mod_deflate (gzip) is your most likely bet for buffering problems. An alternative to consider is writing an HTML file with a refresh statement or using AJAX to get your done-o-dial effect going on.
Kurt