Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send data to the browser while waiting (Python)

Tags:

python

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?

like image 596
Teifion Avatar asked Apr 11 '26 14:04

Teifion


1 Answers

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

like image 94
moinudin Avatar answered Apr 13 '26 05:04

moinudin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!