diff --git a/app.py b/app.py index c0f4e1bd3ae49a2eb0c38a33039f29f129bab05c..231f36fe81062a8e67376f6dae42b27159ba5b53 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,7 @@ from flask import Flask from flask_socketio import SocketIO, send from flask_sqlalchemy import SQLAlchemy +from flask import request from difflib import get_close_matches import time import threading @@ -22,7 +23,7 @@ class QAPair(db.Model): return self.question waiting_time = 10 -last_msg = time.time() + 12 +last_msg = {} question = QAPair.query.with_entities(QAPair.question).all() questions = [a.question for a in question] @@ -36,17 +37,23 @@ def handleMessage(msg): send(ans, broadcast=False) else: send("sorry, I don't understand the question", broadcast = False) + global last_msg - last_msg = time.time() + + last_msg[request.sid] = time.time() def idle_check_thread(): global last_msg global waiting_time while True: current_time = time.time() - if (last_msg + waiting_time) < current_time and (last_msg + waiting_time + 4) > current_time: - socketio.send("are you there?") - time.sleep(5) + try: + for e in last_msg: + if (last_msg[e] + waiting_time) < current_time and (last_msg[e] + waiting_time + 4) > current_time: + socketio.send("are you there?",to= e ) + last_msg[e] = 0 + except: + pass x = threading.Thread(target=idle_check_thread) x.start()