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.

Prompt enhancement stops cleanly when turned off or cancelled

Bowen Xueda89b7f2d546
diff --git a/freevideo_engine/prompt_vlm/service.py b/freevideo_engine/prompt_vlm/service.py
index 481c4f0..49e69da 100644
--- a/freevideo_engine/prompt_vlm/service.py
+++ b/freevideo_engine/prompt_vlm/service.py
@@ -570,8 +570,9 @@ class Service:
releasing = result_received_at[0] if result_received_at else time.monotonic()
if child.poll() is None:
# Killing only the Linux supervisor bypasses its descendant
- # cleanup. Stop the owned group/Windows Job and wait instead.
- processes.stop(child, grace=5)
+ # cleanup. Stop the owned group/Windows Job and wait instead;
+ # the worker finishes its current GPU operation and exits.
+ processes.stop(child, grace=15)
child.wait()
writer.join(timeout=5)
session.close()
diff --git a/freevideo_engine/prompt_vlm/worker.py b/freevideo_engine/prompt_vlm/worker.py
index 9ba4264..0fe96ce 100644
--- a/freevideo_engine/prompt_vlm/worker.py
+++ b/freevideo_engine/prompt_vlm/worker.py
@@ -103,6 +103,31 @@ def available_memory():
return available
+class Cancelled(BaseException):
+ """Raised by a stop signal between Python operations, never inside a GPU call."""
+
+
+def stop_on_signal():
+ """Stop like a finished run: no hard exit while weights or tokens are on their way to the GPU."""
+ import signal
+ names = [signal.SIGTERM, signal.SIGINT] + ([signal.SIGBREAK] if os.name == 'nt' else [])
+ def stop(*_):
+ for name in names:
+ signal.signal(name, signal.SIG_IGN)
+ raise Cancelled()
+ for name in names:
+ signal.signal(name, stop)
+
+
+def settle():
+ torch = sys.modules.get('torch')
+ if torch is not None and torch.cuda.is_initialized():
+ try:
+ torch.cuda.synchronize()
+ except (RuntimeError, OSError):
+ pass
+
+
def emit(**value):
print(json.dumps(value, ensure_ascii=True), flush=True)
@@ -480,6 +505,7 @@ def main():
value = {}
prestarting = os.environ.get(PRESTART_ENV) == '1'
requested = False
+ stop_on_signal()
try:
if prestarting:
started = time.monotonic()
@@ -503,6 +529,10 @@ def main():
else:
value = json.loads(sys.stdin.buffer.read(1024 * 1024))
run(Path(sys.argv[1]), value, stats=stats)
+ except Cancelled:
+ settle()
+ emit(phase='cancelled')
+ return 0
except Exception as error:
if not prestarting or requested:
gpu_snapshot(stats)