title: Handle one HTTP request from python with timeout
body: <p>I would like to write an application where the main thread start an HTTP server what have to wait for exactly one HTTP request for at most 10 seconds. The application have to be blocked until the request is received (and processed) or the timeout is exceeded.</p>
  
  <p>I tried to use this code:</p>
  
  <pre><code>import BaseHTTPServer
  
  class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
      def do_GET(s):
          s.send_response(200)
          s.send_header("Content-type", "text/html")
          s.end_headers()
          s.wfile.write("&lt;html&gt;&lt;head&gt;&lt;title&gt;Title&lt;/title&gt;&lt;/head&gt;")
  
  httpd = BaseHTTPServer.HTTPServer(('', 8001), RequestHandler)
  httpd.socket.settimeout(10)
  httpd.handle_request()
  </code></pre>
  
  <p>The problem is that when the server receives a request, I get this error message:</p>
  
  <pre><code>Exception happened during processing of request from ('127.0.0.1', 51321)
  Traceback (most recent call last):
    File "C:\Python27\lib\SocketServer.py", line 284, in _handle_request_noblock
      self.process_request(request, client_address)
    File "C:\Python27\lib\SocketServer.py", line 310, in process_request
      self.finish_request(request, client_address)
    File "C:\Python27\lib\SocketServer.py", line 323, in finish_request
      self.RequestHandlerClass(request, client_address, self)
    File "C:\Python27\lib\SocketServer.py", line 639, in __init__
      self.handle()
    File "C:\Python27\lib\BaseHTTPServer.py", line 343, in handle
      self.handle_one_request()
    File "C:\Python27\lib\BaseHTTPServer.py", line 313, in handle_one_request
      self.raw_requestline = self.rfile.readline(65537)
    File "C:\Python27\lib\socket.py", line 476, in readline
      data = self._sock.recv(self._rbufsize)
  error: [Errno 10035] A non-blocking socket operation could not be completed immediately
  </code></pre>
  
  <p>If I remove the settimeout function, than I don't get this error, but I lost the timeout also. I tried to use the setblocking function too, but it destroy the effect of the settimeout.</p>
  
  <p>How can I reach my goal?</p>
  
  <p>PS.: I am using Python 2.7.2 on a 64-bit Windows 7</p>