HTTPServer and ThreadingMixIn

C

crowell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top