def communicate(self):
        try:
            while True:
                # (re)set req to None so that if something goes wrong in
                # the RequestHandlerClass constructor, the error doesn't
                # get written to the previous request.
                req = None
                req = self.RequestHandlerClass(self.wfile, self.environ,
                                               self.wsgi_app)
                
                # This order of operations should guarantee correct pipelining.
                req.parse_request()
                if not req.ready:
                    # Something went wrong in the parsing (and the server has
                    # probably already made a simple_response). Return and
                    # let the conn close.
                    return
                
                req.respond()
                if req.close_connection:
                    return
        
        except socket.error, e:
            errnum = e.args[0]
            if errnum == 'timed out':
                # Don't send a 408 if there is no outstanding request; only
                # if we're in the middle of a request.
                # See http://www.cherrypy.org/ticket/853
                if req and req.started_request and not req.sent_headers:
                    req.simple_response("408 Request Timeout")
            elif errnum not in socket_errors_to_ignore:
                if req and not req.sent_headers:
                    req.simple_response("500 Internal Server Error",
                                        format_exc())
            return
        except (KeyboardInterrupt, SystemExit):
            raise
        except FatalSSLAlert, e:
            # Close the connection.
            return
        except NoSSLError:
            if req and not req.sent_headers:
                # Unwrap our wfile
                req.wfile = CP_fileobject(self.socket._sock, "wb", -1)
                req.simple_response("400 Bad Request",
                    "The client sent a plain HTTP request, but "
                    "this server only speaks HTTPS on this port.")
                self.linger = True
        except Exception, e:
            if req and not req.sent_headers:
                req.simple_response("500 Internal Server Error", format_exc())
Read each request and respond appropriately.
dataset/ETHPy150Open cloudera/hue/desktop/core/src/desktop/lib/wsgiserver.py/HTTPConnection.communicate