Non-evil multithreaded WSGI server?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Aug 26 23:47:40 EDT 2008


En Tue, 26 Aug 2008 03:20:53 -0300, Gerhard Häring <gh at ghaering.de>  
escribi�:

> In a recent experiment I've done this:
>
> from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
> from wsgiref.simple_server import make_server, demo_app
> from SocketServer import ThreadingMixIn
>
> # Let's make a WSGI server that can use multiple threads.
>
> class ThreadedHTTPServer(ThreadingMixIn, HTTPServer):
>      """Handle requests in a separate thread."""
>
> # Evil! ;-)
> from wsgiref.simple_server import WSGIServer as MyWSGIServer
> MyWSGIServer.__bases__ = (ThreadedHTTPServer,)
>
> Now I wonder if there's a less evil way that does not involve copy &  
> paste of the WSGIServer code (only couple of lines, but I hate  
> duplication)?!

I'm not sure I understand completely the question - does the code below  
work for you?

class MyWSGIServer(ThreadingMixIn, wsgiref.simple_server.WSGIServer):
     pass

def make_server(
     host, port, app, server_class=MyWSGIServer,  
handler_class=WSGIRequestHandler):
     return wsgiref.simple_server.make_server(host, port, app,  
server_class, handler_class)

-- 
Gabriel Genellina




More information about the Python-list mailing list