web status display for long running program

Peter Hansen peter at engcorp.com
Fri Feb 25 21:58:04 EST 2005


Paul Rubin wrote:
> "Kamilche" <klachemin at comcast.net> writes:
> 
>>I was inspired to enhance your code, and perform a critical bug-fix.
>>Your code would not have sent large files out to dialup users, because
>>it assumed all data was sent on the 'send' command. I added code to
>>check for the number of bytes sent, and loop until it's all gone. I
>>also turned it into a class, and made it 'command' based.
> 
> That server seems to do a cpu-busy loop polling the listening socket
> for incoming requests!  Ouch!  

Not likely, as the socket is blocking by default.  It won't
use any CPU at all until a connection arrives.

> It also assumes that once it's gotten
> \r\n in the input, that the entire request has been received.  

Which is perfectly correct given the OP's specifications,
which were that he simply wanted to hit "Refresh" in his
browser to get a new page.  Note also it's \r\n\r\n, not
just a single one.

> If someone is telnetting into the server typing one character at a time,
> that could fool it.

Fool it how?  We're not talking actual data transfer, just
a simple HTTP request which ends its header section with
the aforementioned sequence, guaranteed.

> I think it's better to just launch a separate thread and use
> BaseHTTPServer which is already in the stdlib.

Very likely.... of course, that wouldn't be any fun. ;-)

-Peter



More information about the Python-list mailing list