'Sets up the live server and databases, and then loops over handling
http requests.'

def run(self):

    if self.connections_override:
        from django.db import connections
        for (alias, conn) in self.connections_override.items():
            connections[alias] = conn
    try:
        handler = StaticFilesHandler(_MediaFilesHandler(WSGIHandler()))
        for (index, port) in enumerate(self.possible_ports):
            try:
                self.httpd = StoppableWSGIServer((self.host, port), QuietWSGIRequestHandler)
            except WSGIServerException as e:
                if (((index + 1) < len(self.possible_ports)) and hasattr(e.args[0], u'errno') and (e.args[0].errno == errno.EADDRINUSE)):
                    continue
                else:
                    raise
            else:
                self.port = port
                break
        self.httpd.set_app(handler)
        self.is_ready.set()
        self.httpd.serve_forever()
    except Exception as e:
        self.error = e
        self.is_ready.set()
