Tomtom84 commited on
Commit
36afd5c
Β·
verified Β·
1 Parent(s): d19d760

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -131,13 +131,18 @@ async def tts(ws: WebSocket):
131
  ids, attn = None, None
132
 
133
  except (StopIteration, WebSocketDisconnect):
134
- pass
135
  except Exception as e:
136
  print("WS‑Error:", e)
137
- await ws.close(code=1011)
 
138
  finally:
139
- if ws.client_state.name!="DISCONNECTED":
140
- await ws.close()
 
 
 
 
141
 
142
  # ── 6.Β Lokaler Test ─────────────────────────────────────────────────
143
  if __name__ == "__main__":
 
131
  ids, attn = None, None
132
 
133
  except (StopIteration, WebSocketDisconnect):
134
+ pass # normales Ende
135
  except Exception as e:
136
  print("WS‑Error:", e)
137
+ if ws.client_state.name != "DISCONNECTED":
138
+ await ws.close(code=1011) # Fehlercode nur, falls noch offen
139
  finally:
140
+ try:
141
+ if ws.client_state.name != "DISCONNECTED":
142
+ await ws.close() # sauberes Close
143
+ except RuntimeError:
144
+ # Starlette hat bereits ein Close‑Frame verschickt
145
+ pass
146
 
147
  # ── 6.Β Lokaler Test ─────────────────────────────────────────────────
148
  if __name__ == "__main__":