def index(): global thread if thread is None: thread = Thread(target=PresidentialCandidate.subscribe) thread.start() ctx = { "namespace": PresidentialCandidate.namespace, "msg_name": PresidentialCandidate.msg_name, "map_data": json.dumps(PresidentialCandidate.current_map_data()), "candidates": CANDIDATES, } return render_template("index.html", **ctx)