I installed a streaming (with Python streams) HTTP server by creating a class that inherits from HTTPServer and ThreadingMixIn:
class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): pass
I have a handler class that inherits from BaseHTTPRequestHandler and I start the server with something like this:
class MyHandler(BaseHTTPRequestHandler): ... server = ThreadedHTTPServer(('localhost', 8080), MyHandler)
This is all pretty simple. The problem I am facing is that ThreadingMixIn, ForkingMixIn or otherwise, the request ends up blocking the request handler for return. This can be easily seen by running this sample code:
class MyHandler(BaseHTTPRequestHandler): def respond(self, status_code): self.send_response(status_code) self.end_headers() def do_GET(self): print "Entered GET request handler" time.sleep(10) print "Sending response!" respond(200)
If the server processed them simultaneously, we could send two requests and see how the server enters both GET request handlers before sending the response. Instead, the server will go into the GET request handler for the first request, wait for it to return, then enter it for the second (so the second request will take ~ 20 seconds to return instead of 10).
Is there an easy way for me to implement a system in which the server does not expect a handler to return? In particular, I am trying to write a system that waits to receive several requests before returning any of them (a long survey form) and run into problems when the first request expects to block any future requests from connecting to the server.
Dylnuge
source share