By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,369 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,369 IT Pros & Developers. It's quick & easy.

BaseHTTPServer threading using SocketServer.ThreadingMixIn

P: n/a
I am making custom web server using HTTPServer and want to be able to
access it simultaneously from different computers. To achieve
multithreading, I have been experimenting with ThreadingMixIn from
SocketServer, but it doesn't seem to work, when I freeze code in one
instance it seems to be frozen in second one too (I experimented with
time.sleep and while 1 loop). I am using python 2.4 on Windows XP. Does
anyone have any suggestions? Do I need to create HTTPRequestHandler
class anything different from ordinary?

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Tortelini" <le*********@gmail.com> writes:
I am making custom web server using HTTPServer and want to be able to
access it simultaneously from different computers. To achieve
multithreading, I have been experimenting with ThreadingMixIn from
SocketServer, but it doesn't seem to work,


One common error is to define your class as something like:

class myServer(HTTPServer, ThreadingMixin): ...

You have to put ThreadingMixin first, since it overrides methods of
TCPServer:

class myServer(ThreadingMixin, HTTPServer): ...
Jul 18 '05 #2

P: n/a
It's not that, here is definition that I use:
class myWebServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
pass

code that runs server:
server = myWebServer(('', 80), myWebHTTPHandler)
LOG("Web Server starting")
server.serve_forever()

and here is shortened version of myWebHTTPHandler:
class myWebHTTPHandler(BaseHTTPServer.BaseHTTPRequestHan dler):
sys_version=""
server_version=versionString

def log_request(self, code='-', size='-'):
pass

def do_GET(self):
my GET code...

def do_POST(self):
my POST code...

Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.