def serve_forever(self):
    while not self.stopped:
        self.handle_request()

def force_stop(self):
    self.server_close()
self.stopped = True
self.create_dummy_request()

def create_dummy_request(self):
    server = xmlrpclib.Server('http://%s:%s' % self.server_address)
server.ping()
How to stop BaseHTTPServer.serve_forever() in a BaseHTTPRequestHandler subclass?