OrbiSubs: retry once when a keep-alive connection is dropped (whisper and LLM)
whisper.cpp closes idle keep-alive connections after ~5 s and we post every ~6 s, so a request can land on a socket the server is closing (RemoteDisconnected on T13, 2026-11-16 22:58:59, no error on gpu02). Timeouts are not retried. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+21
-2
@@ -106,6 +106,25 @@ class MotorLocal:
|
|||||||
return [(w.start, w.end, w.word) for s in segs for w in (s.words or [])]
|
return [(w.start, w.end, w.word) for s in segs for w in (s.words or [])]
|
||||||
|
|
||||||
|
|
||||||
|
def post_reintento(sesion, url, **kw):
|
||||||
|
"""POST con un solo reintento si se cortó la conexión.
|
||||||
|
|
||||||
|
Caso real (T13, 2026-11-16 22:58:59): RemoteDisconnected en un pedido a whisper.cpp,
|
||||||
|
sin ningún error en gpu02. Mandamos un pedido cada ~6 s por una conexión keep-alive y
|
||||||
|
el server (cpp-httplib) cierra las inactivas a los ~5 s. Si el pedido sale justo
|
||||||
|
cuando el server cierra, llega a un socket muerto. Reintentar abre una conexión nueva.
|
||||||
|
Es seguro: /inference y chat/completions no cambian estado en el server.
|
||||||
|
Un timeout NO se reintenta: ahí el motor está lento y repetir lo carga más."""
|
||||||
|
import requests
|
||||||
|
try:
|
||||||
|
return sesion.post(url, **kw)
|
||||||
|
except requests.exceptions.ConnectionError as e:
|
||||||
|
if isinstance(e, requests.exceptions.Timeout):
|
||||||
|
raise
|
||||||
|
log("http_retry", url=url, err=str(e)[:200])
|
||||||
|
return sesion.post(url, **kw)
|
||||||
|
|
||||||
|
|
||||||
class MotorHTTP:
|
class MotorHTTP:
|
||||||
"""whisper.cpp server remoto (gpu02, tarea 076-agregado): solo POST /inference,
|
"""whisper.cpp server remoto (gpu02, tarea 076-agregado): solo POST /inference,
|
||||||
un pedido a la vez (este proceso es secuencial). Nunca /load: cambia el modelo
|
un pedido a la vez (este proceso es secuencial). Nunca /load: cambia el modelo
|
||||||
@@ -129,8 +148,8 @@ class MotorHTTP:
|
|||||||
data["prompt"] = prompt
|
data["prompt"] = prompt
|
||||||
t = time.time()
|
t = time.time()
|
||||||
try:
|
try:
|
||||||
r = self.s.post(self.url, files={"file": ("a.wav", b.getvalue(), "audio/wav")}, data=data,
|
r = post_reintento(self.s, self.url, files={"file": ("a.wav", b.getvalue(), "audio/wav")},
|
||||||
timeout=self.timeout)
|
data=data, timeout=self.timeout)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
d = r.json()
|
d = r.json()
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
+5
-4
@@ -18,7 +18,7 @@ import argparse, json, os, statistics, time
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from orbisubs import escribir_atomico, log, partir_lineas, ts_vtt
|
from orbisubs import escribir_atomico, log, partir_lineas, post_reintento, ts_vtt
|
||||||
|
|
||||||
SISTEMA = ("You translate live Chilean Spanish TV captions into natural, concise English. "
|
SISTEMA = ("You translate live Chilean Spanish TV captions into natural, concise English. "
|
||||||
"Keep proper names, place names and Chilean acronyms (e.g. Carabineros, PDI, SII, AFP, Fonasa) as they are. "
|
"Keep proper names, place names and Chilean acronyms (e.g. Carabineros, PDI, SII, AFP, Fonasa) as they are. "
|
||||||
@@ -42,9 +42,10 @@ class Traductor:
|
|||||||
t = time.time()
|
t = time.time()
|
||||||
self.error = None
|
self.error = None
|
||||||
try:
|
try:
|
||||||
r = self.s.post(self.url, json={"model": self.modelo, "temperature": 0, "max_tokens": 160,
|
# Mismo keep-alive que con whisper: un corte de conexión se reintenta una vez.
|
||||||
"chat_template_kwargs": {"enable_thinking": False},
|
r = post_reintento(self.s, self.url, json={"model": self.modelo, "temperature": 0, "max_tokens": 160,
|
||||||
"messages": msgs}, timeout=self.timeout)
|
"chat_template_kwargs": {"enable_thinking": False},
|
||||||
|
"messages": msgs}, timeout=self.timeout)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
en = r.json()["choices"][0]["message"]["content"].strip().strip('"').strip()
|
en = r.json()["choices"][0]["message"]["content"].strip().strip('"').strip()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user