def do_GET(self):
    if self.path == '/shutdown':
        t = threading.Thread(target=self.server.shutdown)
t.daemon = True
t.start()
How to stop a simplehttpserver in python from httprequest handler?