fix(live): a dead output stops the stream even after a good frame
The failure cap read `consecutive_failures >= FAILURE_LIMIT and captured == 0`, so it could only ever fire on a cold start. An output removed while someone was watching -- grim answering "unknown output" to every grab from then on -- kept the loop retrying twice a second for as long as the viewer held the page open. That is the busy loop the cap exists to stop, so the count is now of failures in a row and nothing else. Giving up stays sticky: a removed output does not come back, and re-enabling the session is how it returns. While here, the capture thread is named for its output and the give-up is logged by output. The phrase is the stream's only credential, and faulthandler, `threading.excepthook` and any sampling profiler all print thread names. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01URhyHGQnmKH9zBXxoznfQY
This commit is contained in:
1 parent
9744d35945
commit
52e3786bfb
3 files changed
+92
-10
No files matched your search
@@ -25,11 +25,19 @@ PHRASE = "amber-otter-lantern-harbor-7k2qp"
|
||||
|
||||
|
||||
class StubCapture:
|
||||
"""A `Capture` under the test's control: counts grabs, can be told to fail."""
|
||||
"""A `Capture` under the test's control: counts grabs, can be told to fail.
|
||||
|
||||
def __init__(self, frames=None, fail_first: int = 0, delay: float = 0.0):
|
||||
`fail_first` is a capture that is broken from the start (a cold start that
|
||||
never works); `fail_after` is one that works and then stops -- the output
|
||||
was removed while someone was watching, which is grim's "unknown output" on
|
||||
every grab from then on.
|
||||
"""
|
||||
|
||||
def __init__(self, frames=None, fail_first: int = 0, delay: float = 0.0,
|
||||
fail_after: int | None = None):
|
||||
self.frames = list(frames) if frames else [jpeg_bytes(i) for i in range(1, 50)]
|
||||
self.fail_first = fail_first
|
||||
self.fail_after = fail_after
|
||||
self.delay = delay
|
||||
self.calls = 0
|
||||
self._lock = threading.Lock()
|
||||
@@ -42,6 +50,8 @@ class StubCapture:
|
||||
time.sleep(self.delay)
|
||||
if call <= self.fail_first:
|
||||
raise RuntimeError(f"stub capture failing on purpose (call {call})")
|
||||
if self.fail_after is not None and call > self.fail_after:
|
||||
raise RuntimeError(f"stub capture: unknown output (call {call})")
|
||||
return self.frames[(call - 1 - self.fail_first) % len(self.frames)]
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user