title: python httpserver on separate thread
body: <p>I am trying to create an httpserver on a separate thread which should process a single get request and shutdown if a single parameter is passed in the url.</p>
  
  <pre><code>import sys
  import threading
  import BaseHTTPServer
  from SimpleHTTPServer import SimpleHTTPRequestHandler
  
  class WebServer(SimpleHTTPRequestHandler,threading.Thread):
      port = 9000
      protocol_version = "HTTP/1.1"
      code = ""        
      httpd = None
      isRunning = False
      def do_GET(self):
          self.send_response(200)
          self.send_header("Content-type","text/html")
          self.end_headers()
          self.wfile.write("webpage")
          try:
              self.code = split(self.path,"=")[1]
          except:
              pass
          else:
              self.isRunning=False
              self.stop()            
      def do_POST(self):
          pass
      def __init__(self,port=9000):
          threading.Thread.__init__(self)
          self.port=port
      def run(self):
          while True:
              server_address = ("127.0.0.1",self.port)
              try:
                  self.httpd = BaseHTTPServer.HTTPServer(server_address,WebServer)
              except:
                  self.port +=1
              else:
                  break
          self.isRunning=True
          self.httpd.serve_forever()
  
  server = WebServer(1)
  server.start()
  while(server.isRunning==False):
      pass
  print "Server running on port: %d" %(server.port)
  server.join()
  print "code: "+server.code
  </code></pre>
  
  <p>But an error occurs when a request is sent to it:</p>
  
  <pre><code>Server running on port: 1025
  ----------------------------------------
  Exception happened during processing of request from ('127.0.0.1', 56462)
  Traceback (most recent call last):
    File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
      self.process_request(request, client_address)
    File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
      self.finish_request(request, client_address)
    File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
      self.RequestHandlerClass(request, client_address, self)
  TypeError: __init__() takes at most 2 arguments (4 given)
  ----------------------------------------
  </code></pre>
  
  <p>when using curl to connect to the server,it gives this error:</p>
  
  <pre><code>curl: (52) Empty reply from server 
  </code></pre>