Skip to content

Make videos on the computer you already own. FreeVideo runs MiniMax H3 in as little as 8 GB of VRAM and 16 GB of RAM, and adapts its acceleration path to your hardware.

Preload: remove the unfinished record file a stopped worker leaves beside the video

Bowen Xue562f05fa8d09
diff --git a/freevideo_engine/idle_encoder.py b/freevideo_engine/idle_encoder.py
index f4c8b3f..ccda294 100644
--- a/freevideo_engine/idle_encoder.py
+++ b/freevideo_engine/idle_encoder.py
@@ -5,6 +5,7 @@ CUDA, and a new foreground request cancels this lower-priority work first.
"""
import argparse
from contextlib import contextmanager
+import glob
import json
import os
import signal
@@ -117,6 +118,20 @@ def interruptible_load(patcher, check):
delattr(obj, name)
+def discard_staging(report):
+ """Remove what a stopped preload left of an unfinished save.
+
+ A worker that does not yield in time is stopped, sometimes between
+ creating save()'s staging file and renaming it; the empty file would stay
+ beside the user's video. Only this record's own staging names are removed.
+ """
+ for path in report.parent.glob(glob.escape(report.name) + '.*.tmp'):
+ try:
+ path.unlink()
+ except OSError:
+ pass
+
+
class IdleEncoder:
def __init__(self):
self.thread = None
@@ -205,6 +220,8 @@ class IdleEncoder:
if self.process is not None and self.process.poll() is None:
processes.stop(self.process, grace=1.)
save(report, dict(state='failed', reason=str(error), error_type=type(error).__name__))
+ finally:
+ discard_staging(report)
self.thread = threading.Thread(target=work, name='FreeVideo idle encoder', daemon=True)
self.thread.start()
diff --git a/freevideo_engine/resident_process.py b/freevideo_engine/resident_process.py
index a16607c..6284866 100644
--- a/freevideo_engine/resident_process.py
+++ b/freevideo_engine/resident_process.py
@@ -403,9 +403,10 @@ class SessionOwner:
if self.prewarm is not None:
stopped = self.prewarm.stop()
from .encoder_diagnostics import prewarm_receipt
+ from .idle_encoder import discard_staging
receipt = prewarm_receipt(self.prewarm.report, gpu=True)
receipt['worker_released'] = False
- self.prewarm = None
+ report, self.prewarm = self.prewarm.report, None
# An interrupted native loader can be stuck in IO. Never grant
# memory credit or start another request until it yielded/exited.
if self.process is not None and self.process.poll() is None:
@@ -417,6 +418,9 @@ class SessionOwner:
processes.stop(self.process, grace=1.)
self.process = None
receipt['worker_released'] = True
+ # The worker writes the same record and may have been stopped inside that save.
+ if report is not None:
+ discard_staging(report)
return receipt
def warm_encoder(self, output, python, environment, *, busy=None, notify=None):