concurrent.futures ( stdlib Python 3.2):
from BaseHTTPServer import HTTPServer, test
from SimpleHTTPServer import SimpleHTTPRequestHandler
from SocketServer import ThreadingMixIn
from concurrent.futures import ThreadPoolExecutor
class PoolMixIn(ThreadingMixIn):
def process_request(self, request, client_address):
self.pool.submit(self.process_request_thread, request, client_address)
def main():
class PoolHTTPServer(PoolMixIn, HTTPServer):
pool = ThreadPoolExecutor(max_workers=40)
test(HandlerClass=SimpleHTTPRequestHandler, ServerClass=PoolHTTPServer)
if __name__=="__main__":
main()
, .
server.py, :
$ python -mserver
40 http://your_host:8000/.
HTTPServer .