1

Possible Duplicate:
python print function in real time

I am developing a python cgi web application, which retrieves large information(millions of lines) from the database. For that i will be running a loop (print statements are in the loop).

How do i print out the information continuosly on the browser as the script retrieves from the database? In my case, suppose the loop runs for 1000 times, the webpage is returned only after the script completes all the loops. Sometimes the script takes more than 5 minutes with few options and server gives me timeout error. To avoid the request timing out, i need to have the server-side script return something every so often to reassure the browser that the server hasn't died and a result will be forthcoming. I am using the HTTP header print "Content-type:text/html\r\n\r\n". I got to know about the HTTP Header "Transfer-Encoding: chunked". How do i use it in Python? I would appreciate if you can give me any suggestions. Thank you so much.

Regards, Sushil.

Community
  • 1
  • 1
Sushil
  • 53
  • 5
  • Possible duplicate question [http://stackoverflow.com/questions/7463878/python-print-function-in-real-time](http://stackoverflow.com/questions/7463878/python-print-function-in-real-time) – brc Sep 18 '11 at 20:53
  • 1
    @brc If you don't have enough rep to vote to close as a duplicate, flag it "it doesn't belong here" -> "exact duplicate". – agf Sep 20 '11 at 23:58

0 Answers0