HTTPServer and ThreadingMixIn
crowell at mit.edu
crowell at mit.edu
Mon May 15 17:39:28 EDT 2006
Hello,
I am having trouble getting the ThreadingMixIn to do what I want.
Looking over the docs (and some old code I wrote which successfully
does what I want), I arrived at the following:
import time
import SocketServer
import BaseHTTPServer
class TheServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
pass
class TheHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_GET(self):
print "sleeping..."
time.sleep(10)
print "awake!"
if __name__ == "__main__":
theServer = TheServer(('', 8083), TheHandler)
theServer.serve_forever()
I would like this server to print "sleeping..." when someone make a
request, waits 10 seconds, then prints "awake!" This works, but it
does not exhibit threading behavior; i.e. it handles the requests in
sequential order:
sleeping...
awake!
sleeping...
awake!
Is there some problem with using the time.sleep() method? Or have I
done something else wrong? Sorry for asking such a simple question,
but it seems I am unable to pinpoint my error.
Thanks.
--Rob
More information about the Python-list
mailing list