Is there a way to make BaseHTTPServer.HTTPServer be multi-threaded like SocketServer.ThreadingTCPServer?
-
Is there a reason why you need it to be?jakebman– jakebman2010-03-07 22:29:44 +00:00Commented Mar 7, 2010 at 22:29
-
3Because I want a basic web server that can handle concurrency? I also don't need/want an all out framework like web.py, cherrypy or anything like that, I just want a really basic webserver like BaseHTTPServer that can handle multiple concurrent requests.Ian– Ian2010-03-07 22:32:52 +00:00Commented Mar 7, 2010 at 22:32
-
Use Apache and mod_wsgi.user297524– user2975242010-03-19 16:20:58 +00:00Commented Mar 19, 2010 at 16:20
-
1here is a reference: link, threading, forkingsfossen– sfossen2010-04-08 17:52:56 +00:00Commented Apr 8, 2010 at 17:52
Add a comment
|
1 Answer
You can simply use the threading mixin using both of those classes to make it multithread :)
It won't help you much in performance though, but it's atleast multithreaded.
from SocketServer import ThreadingMixIn
from BaseHTTPServer import HTTPServer
class MultiThreadedHTTPServer(ThreadingMixIn, HTTPServer):
pass
6 Comments
Ian
This looks like a solution.. however I'd rather opt to write my own server than use something slow.. :(
Wolph
If you're simply looking for hosting Python than why not use an existing http server like nginx, apache or lighttpd? As for the performance, threading it will allow you to make multiple concurrent connections without blocking so in the case of multiple simultaneous requests it will be faster. But it will still use only 1 processor.
Ian
I'm not looking for that, I'm making a Queue server that takes incoming requests (http or some similar format) and does an action based on the request.
Buzz Moschetti
For quicky POC imps, this is a great way to allow multiple connections to not step on each other's comm buffers. Thanks for sharing.
|