I need a HTTP server handling long lasting requests e.g. 10-30 seconds. Below is a pice of the code. In order to make the server reponsive while handling othere requests I use SocketServer.ThreadingMixIn.


However the problem is the it does not work out. I checked thet a new thread is created for each new connection new, but the main loop seems to be frozen until the prevoius handling ends.

What could go wrong?

Thanks, Andy



* * *

import os
import time
import BaseHTTPServer
import SocketServer
import threading
import sys

class
SimpleHTTPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
        response="aaaaaaaaaaaaaaaa"+str(time.time())
        self.send_response(200)
        self.send_header("Content-type",'text/plain')

self.send_header("Content-Length",len(response))
        self.end_headers()
        time.sleep(10) #simulation of the processing
        self.wfile.write(response)

    def do_POST(self):
        self.do_GET()

class
myWebServer(SocketServer.ThreadingMixIn,BaseHTTPServer.HTTPServer):
  pass

if __name__ == '__main__':
    server_address = ('',80)
    httpd=myWebServer(server_address,SimpleHTTPRequestHandler)
    sa=httpd.socket.getsockname()
    print "Serving HTTP on", sa[0], "port", sa[1],"..."
    httpd.serve_forever()
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to