HTTPServer and ThreadingMixIn

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • crowell@mit.edu

    #1

    HTTPServer and ThreadingMixIn

    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(Socke tServer.Threadi ngMixIn,
    BaseHTTPServer. HTTPServer):
    pass

    class TheHandler(Base HTTPServer.Base HTTPRequestHand ler):
    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

Working...