How can I restart a BaseHTTPServer instance?
<p>This is what I have:</p>

<p>http.py:</p>

<pre><code>class HTTPServer():

    def __init__(self, port):
        self.port = port
        self.thread = None
        self.run = True
    def serve(self):
        self.thread = threading.Thread(target=self._serve)
        self.thread.start()
    def _serve(self):
        serverAddress = ("", self.port)
        self.server = MyBaseHTTPServer(serverAddress,MyRequestHandler)
        logging.log(logging.INFO, "HTTP server started on port %s"%self.port)
        while self.run:
            self.server.handle_request()
    def stop(self):
        self.run = False
        self.server.server_close()
</code></pre>

<p>Then in another file, to restart it:</p>

<pre><code>def restartHTTP(self):
    try:
        self.httpserver.stop()
        reload(http)
        self.httpserver = http.HTTPServer(80)
        self.httpserver.serve()
    except:
        traceback.print_exc()
</code></pre>

<p>This gives me an address already in use error, so it seems the HTTP server isn't stopping properly. What else do I need to do to stop it?</p>

<p>EDIT: </p>

<p>Where I call restartHTTP:</p>

<pre><code>def commandHTTPReload(self, parts, byuser, overriderank):
    self.client.factory.restartHTTP()
    self.client.sendServerMessage("HTTP server reloaded.")
</code></pre>

<p>I do know the command is executing because I get the message it's supposed to send.</p>
