title: Python BaseHTTPServer - prevent errors ("connection reset by peer," etc.) from ruining curses display
body: <p>I have a Python script that implements a built-in web server:</p>
  
  <pre><code>class http_server(BaseHTTPRequestHandler):
      def log_message(self, format, *args):
        # prevent the BaseHTTPServer log messages, we use our own logging instead
        return
      def do_GET(self):
        log("responding to http request from %s: %s" % (self.client_address[0], self.path))
        text_string = "Hello World"
        self.send_response(200)
        self.send_header("Content-type", "text/plain")
        self.send_header("Content-Length", len(text_string))
        self.end_headers()
        self.wfile.write(text_string)
  
  def start_server():
    try:
      httpd = SocketServer.TCPServer(("", 8888), http_server)
      httpd.serve_forever()
    except Exception as e:
        cleanup(None, None)
        print "Error starting internal http server: %s" % repr(e)
        sys.exit(1)
  
  # main script
  # does various things, initializes curses, etc.
  start_server()
  </code></pre>
  
  <p>This works fine, however the problem is that the python script also implements an on-screen status display using curses running in another thread. When an error occurs in the HTTP server (e.g. "connection reset by peer", etc.) the python traceback indicating said error gets splattered across my nice curses display.</p>
  
  <p>I have tried adding <code>try...exception</code> blocks around the <code>do_GET</code> portion of my <code>BaseHTTPRequestHandler</code> class but that had no effect.</p>
  
  <p>How can I silence Python traceback messages in this code?</p>