SimpleHTTPRequestHandler handling long lasting requests problem

A

Andy Leszczynski

I need a HTTP server handling long lasting requests e.g. 10-30 seconds.
Below is a pice of the code. In order to make the server reponsive while
handling othere requests I use SocketServer.ThreadingMixIn.

However the problem is the it does not work out. I checked thet a new
thread is created for each new connection new, but the main loop seems
to be frozen until the prevoius handling ends.

What could go wrong?

Thanks, Andy



* * *

import os
import time
import BaseHTTPServer
import SocketServer
import threading
import sys

class
SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
response="aaaaaaaaaaaaaaaa"+str(time.time())
self.send_response(200)
self.send_header("Content-type",'text/plain')

self.send_header("Content-Length",len(response))
self.end_headers()
time.sleep(10) #simulation of the processing
self.wfile.write(response)

def do_POST(self):
self.do_GET()

class
myWebServer(SocketServer.ThreadingMixIn,BaseHTTPServer.HTTPServer):
pass

if __name__ == '__main__':
server_address = ('',80)
httpd=myWebServer(server_address,SimpleHTTPRequestHandler)
sa=httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1],"..."
httpd.serve_forever()
 
A

Andy Leszczynski

Sorry for questioning Python :) - it turned out that this is a problem
with Mozilla. For some reason it holds up with opening second connection
to given host until the previous one is completed. Interestingly enough,
IE works better with Python multi threaded server in that regard.

Thx, A.
 
S

Steve Holden

Andy said:
Sorry for questioning Python :) - it turned out that this is a problem
with Mozilla. For some reason it holds up with opening second connection
to given host until the previous one is completed. Interestingly enough,
IE works better with Python multi threaded server in that regard.

Thx, A.

Try switching keepalives off, or falling back to HTTP 1.0 - ironically
it may be the attempt to use the same connection for both pieces of
content that holds things up.

regards
Steve
 
A

Andy Leszczynski

Steve said:
Try switching keepalives off, or falling back to HTTP 1.0 - ironically
it may be the attempt to use the same connection for both pieces of
content that holds things up.

regards
Steve

I tested it before and it did not work either. Have to try HTTP 1.0 thouh.

Thanks, A.
 
A

Andy Leszczynski

Steve said:
Try switching keepalives off, or falling back to HTTP 1.0 - ironically
it may be the attempt to use the same connection for both pieces of
content that holds things up.

regards
Steve

I tested it before and it did not work either. Have to try HTTP 1.0 thouh.

Thanks, A.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top