Spaces:
Paused
Paused
Commit
·
ac443a4
1
Parent(s):
7ace067
- accelerator.py +6 -0
accelerator.py
CHANGED
@@ -2,11 +2,15 @@ from typing import Union
|
|
2 |
from fastapi.websockets import WebSocket, WebSocketState
|
3 |
|
4 |
class Accelerator:
|
|
|
|
|
5 |
ws: Union[WebSocket, None] = None
|
6 |
|
7 |
def connected(self):
|
8 |
if self.ws == None: return False
|
9 |
|
|
|
|
|
10 |
if self.ws.client_state == WebSocketState.CONNECTED:
|
11 |
return True
|
12 |
else:
|
@@ -20,3 +24,5 @@ class Accelerator:
|
|
20 |
async def accelerate(self, input):
|
21 |
await self.ws.send_text(input)
|
22 |
return await self.ws.receive_text()
|
|
|
|
|
|
2 |
from fastapi.websockets import WebSocket, WebSocketState
|
3 |
|
4 |
class Accelerator:
|
5 |
+
def __del__(self): self.ws.close()
|
6 |
+
|
7 |
ws: Union[WebSocket, None] = None
|
8 |
|
9 |
def connected(self):
|
10 |
if self.ws == None: return False
|
11 |
|
12 |
+
print(f"===== client_state: {self.ws.client_state}")
|
13 |
+
|
14 |
if self.ws.client_state == WebSocketState.CONNECTED:
|
15 |
return True
|
16 |
else:
|
|
|
24 |
async def accelerate(self, input):
|
25 |
await self.ws.send_text(input)
|
26 |
return await self.ws.receive_text()
|
27 |
+
|
28 |
+
|