serve_forever() and non-blocking connection
Steve Holden
sholden at holdenweb.com
Sun Sep 8 15:26:10 EDT 2002
"Colin Thefleau" <quatrelle at gmx.ch> wrote in message
news:ale100$bj4$1 at nets3.rz.RWTH-Aachen.DE...
> Hi
>
> I have a problem programing a small proxy with non-blocking sockets. I
> guess asyncore would be better, but I have no idea how to implement it
> and the application is runing now (just too slow).
> So I would like to use threads. First here a small example of what I use
> for the connection (inside a function):
>
> http_proxy = HTTPServer(configuration.listen, RequestHandler)
> http_proxy.serve_forever()
>
> Now this serve_forever() process one request at a time.
> Ok this is working but too slow. I tried to to use handle_request()
> instead of serve_forever() in a while loop and put some
>
> thread.start_new_thread(http_proxy.handle_request, ())
>
> in there. But this looks too dirty and apparently does not help much.
>
> So here my newbee question: what would be the (better) right approach to
> be able so serve many connections at the same time? Knowing that each
> process can be quite CPU hungry.
>
> Any advice is greatly aprecieted
Try using the ThreadingMixIn, something like this
class ThreadingHTTPServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer)
...
http_proxy = ThreadingHTTPServer(configuration.listen, RequestHandler)
http_proxy.serve_forever()
regards
-----------------------------------------------------------------------
Steve Holden http://www.holdenweb.com/
Python Web Programming pydish.holdenweb.com/pwp/
Previous .sig file retired to www.homeforoldsigs.com
-----------------------------------------------------------------------
More information about the Python-list
mailing list