rohan13 commited on
Commit
aa2ddf1
1 Parent(s): 59d5d05

handling negative use cases

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -21,11 +21,17 @@ def handle_message(data):
21
  question = data['question']
22
  print("question: " + question)
23
 
24
- future = executor.submit(run, question)
25
- response = future.result()
26
-
27
- emit('response', {'response': response})
28
-
 
 
 
 
 
 
29
 
30
  if __name__ == '__main__':
31
  socketio.run(app, host="0.0.0.0", port=7860)
 
21
  question = data['question']
22
  print("question: " + question)
23
 
24
+ if len(executor.threads) >= executor.max_workers:
25
+ emit('response', {'response': 'Server is busy, please try again later'})
26
+ return
27
+
28
+ try:
29
+ future = executor.submit(run, question)
30
+ response = future.result()
31
+ emit('response', {'response': response})
32
+ except Exception as e:
33
+ print(f"Error processing request: {str(e)}")
34
+ emit('response', {'response': 'Server is busy. Please try again later.'})
35
 
36
  if __name__ == '__main__':
37
  socketio.run(app, host="0.0.0.0", port=7860)