THRIFT-597. py: Python THttpServer performance improvements

This enables buffered I/O and ThreadingMixin.

Patch: David Reiss

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@991971 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bryan Duxbury 2010-09-02 15:14:27 +00:00
parent f2ef59ffbf
commit d6a02ff99b

View File

@ -29,7 +29,8 @@ class THttpServer(TServer.TServer):
acting as a mock version of an Apache-based PHP Thrift endpoint."""
def __init__(self, processor, server_address,
inputProtocolFactory, outputProtocolFactory = None):
inputProtocolFactory, outputProtocolFactory = None,
server_class = BaseHTTPServer.HTTPServer):
"""Set up protocol factories and HTTP server.
See BaseHTTPServer for server_address.
@ -52,12 +53,14 @@ class THttpServer(TServer.TServer):
itrans = TTransport.TFileObjectTransport(self.rfile)
otrans = TTransport.TFileObjectTransport(self.wfile)
itrans = TTransport.TBufferedTransport(itrans, int(self.headers['Content-Length']))
otrans = TTransport.TBufferedTransport(otrans)
iprot = thttpserver.inputProtocolFactory.getProtocol(itrans)
oprot = thttpserver.outputProtocolFactory.getProtocol(otrans)
thttpserver.processor.process(iprot, oprot)
otrans.flush()
self.httpd = BaseHTTPServer.HTTPServer(server_address, RequestHander)
self.httpd = server_class(server_address, RequestHander)
def serve(self):
self.httpd.serve_forever()