diff --git a/comm/server/main.py b/comm/server/main.py index 4caed053b1ba2ad0a249991d042d43c93c86d0bc..f7e6ee2c2a7f0820ad7704a8c2f88f237941226d 100644 --- a/comm/server/main.py +++ b/comm/server/main.py @@ -32,7 +32,7 @@ app_args = {} questions = None clients = None current_seed = 1 -wsq = None +wsq = {} def load_questions(): global app_args @@ -213,7 +213,9 @@ def post(): with open(save_file_path, "w") as fp: json.dump(dat, fp, indent=4) - wsq.put(dat) + for k, v in wsq.items(): + if v is not None: + v.put(dat) res = {"status": "OK"} @@ -360,7 +362,7 @@ def save_best_solution(): with open(out_file_path, 'w') as fp: fp.write(questions[qname]['answers'][_best_json]['answer']) - questions[_name]["status"] = "Saved" + questions[qname]["status"] = "Saved" questions[qname]['best_json'] = _best_json res = {"status": "OK"} @@ -600,14 +602,15 @@ def ws(): if request.environ.get('wsgi.websocket'): ws = request.environ['wsgi.websocket'] + ws_id = time.time() + wsq[ws_id] = Queue() + while True: - if wsq is None: - time.sleep(1) - continue - else: - data = wsq.get() - str_data = json.dumps(data) - ws.send(str_data) + data = wsq[ws_id].get() + str_data = json.dumps(data) + ws.send(str_data) + + wsq[ws_id] = None @app.route("/") def index(): @@ -653,9 +656,6 @@ def init_system(): if questions is None: load_questions() - if wsq is None: - wsq = Queue() - if __name__ == "__main__": parser = argparse.ArgumentParser(description="PYNQ control panel.") diff --git a/comm/server/static/js/pynq-manager.js b/comm/server/static/js/pynq-manager.js index 8361e2a63018fe3ae98098683f7ccea2dcfee601..534a61f06c76c2f1751f8e367612b8338a1715a6 100644 --- a/comm/server/static/js/pynq-manager.js +++ b/comm/server/static/js/pynq-manager.js @@ -209,6 +209,7 @@ $(function(){ data: {qname: qname} }).done((data) => { alert(data['status']); + location.reload(); }); }); $("#client-control-pane").find(".submit-button").eq(0).click(function(){