thread = threading.Thread(target=server.serve_forever)
thread.daemon = True
thread.start()

def fin():
    server.shutdown()
print('server running on port {}'.format(server.server_port))
How do I kill SimpleHTTPServer from within a Python script?