Sockets/Threads/ThreadingTCPServer and other NASTY things...

gbgbgb at gmx.de gbgbgb at gmx.de
Thu May 3 09:24:03 EDT 2001


Hi!
I am writing an Applicationserver for CGI-Scripts using
ThreadingTCPServer.
I my BaseHTTPRequestHandler I am handling the call in do_GET/do_POST.
My problem is that the response I am writing sometimes gets crippled,
about every five times. (Crippled meens that the data is truncated or
even no response is getting back)

My send-routine looks like this:

    def dah_writeResponse(self, header, data):

	data_len = len(data)
	
	start_time = time.time()

	self.wfile.write("%s %s %s\r\n" % (self.protocol_version, "200", ""))
	self.wfile.write("%s: %s\r\n" % ("Content-Length", str(data_len)))
	self.wfile.write("%s: %s\r\n" % ("Date", self.date_time_string()))
	self.wfile.write("%s: %s\r\n" % ("Server", Server_ID))
	self.wfile.write("%s: %s\r\n" % ("Connection", "Close"))
	self.wfile.write(header + "\r\n\r\n")

	self.wfile.write(data)
	self.wfile.flush()

	slice = 0
	l = len(data)
	print "(" + str(l) + " bytes response written in " + str(time.time()
- start_time) + ")"
	sys.stdout.flush()

	time.sleep(1)

Without the time.sleep(1) call it does not work at all. The most funny
thing is, that under Internetexplorer it works worse than with
Netscape.

Is there maybe some "mystical" HTTP-HEADER needed? "keep-alive"? Is
the flushing bad? What else could be the problem? Has it something to
do with the Threads?

Has anybody an idea? 
This is driving me mad!!

yours in hope
Gunter





More information about the Python-list mailing list