DaniilAlpha commited on
Commit
3518fdf
·
1 Parent(s): 0dc748d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +14 -6
main.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  from fastapi import FastAPI, WebSocket
2
  from fastapi.responses import HTMLResponse
3
 
@@ -60,15 +62,21 @@ async def answer(ws: WebSocket):
60
  await ws.accept()
61
 
62
  print("ws connected!")
63
-
 
 
 
 
64
  input = await ws.receive_text()
65
- output = answerer(input, 32)
 
 
 
 
 
 
66
 
67
  print("output ready!")
68
-
69
- for el in output:
70
- print(f"sent: '{el}'")
71
- await ws.send_text(el)
72
 
73
  await ws.close()
74
 
 
1
+ from threading import Thread
2
+
3
  from fastapi import FastAPI, WebSocket
4
  from fastapi.responses import HTMLResponse
5
 
 
62
  await ws.accept()
63
 
64
  print("ws connected!")
65
+
66
+ async def callback(output: str):
67
+ print(f"sent: '{output}'")
68
+ await ws.send_text(output)
69
+
70
  input = await ws.receive_text()
71
+ answerer_thread = Thread(
72
+ target=answerer,
73
+ args=(input, 32),
74
+ kwargs={"callback": callback}
75
+ )
76
+ answerer_thread.start()
77
+ answerer_thread.join()
78
 
79
  print("output ready!")
 
 
 
 
80
 
81
  await ws.close()
82