title: Python: run SimpleHTTPServer and make request to it in a script
body: <p>I would like to write Python script that would:</p>
  
  <ol>
  <li>Start SimpleHTTPServer on some port</li>
  <li>Make a request to the server and send some data via POST</li>
  <li>Run script via shell in interactive mode and interact with it</li>
  </ol>
  
  <p>Right now the code looks like this:</p>
  
  <pre><code>import SimpleHTTPServer
  import SocketServer
  import urllib
  import urllib2
  
  # Variables
  URL = 'localhost:8000'
  PORT = 8000
  
  # Setup simple sever
  Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
  httpd = SocketServer.TCPServer(("", PORT), Handler)
  print "serving at port", PORT
  httpd.serve_forever()
  
  # Getting HTML from the target page
  values = {
      'name': 'Thomas Anderson',
      'location': 'unknown'
  }
  data = urlilib.urlencode(values)
  req = urllib2.Request(url, data)
  response = urllib2.urlopen(req)
  html = response.read()
  </code></pre>
  
  <p>The problem is that once I run my script</p>
  
  <pre><code>python -i foo.py
  </code></pre>
  
  <p>It prints <code>serving at port 8000</code> and then freezes. I bet this is something trivial for Python gurus here, but help would be appreciated.</p>