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.

Image generation on Windows no longer stalls while the image model loads

Bowen Xued74c5c392494
diff --git a/freevideo_engine/image_gen/worker.py b/freevideo_engine/image_gen/worker.py
index 2839488..ec5d8ce 100644
--- a/freevideo_engine/image_gen/worker.py
+++ b/freevideo_engine/image_gen/worker.py
@@ -2,6 +2,7 @@
import argparse
from contextlib import ExitStack, redirect_stdout
import json
+import os
from pathlib import Path
import queue
import sys
@@ -150,7 +151,11 @@ def main():
args = parser.parse_args()
if not 0 < args.idle_seconds < float('inf'):
parser.error('--idle-seconds must be positive and finite')
- serve(args.pack_dir, device=args.device, idle_seconds=args.idle_seconds)
+ stream = None
+ if os.name == 'nt':
+ from ..win32 import private_stdin
+ stream = private_stdin()
+ serve(args.pack_dir, device=args.device, idle_seconds=args.idle_seconds, stream=stream)
return 0
diff --git a/freevideo_engine/win32.py b/freevideo_engine/win32.py
index d3b8cd5..d01ddb3 100644
--- a/freevideo_engine/win32.py
+++ b/freevideo_engine/win32.py
@@ -40,6 +40,7 @@ def kernel32():
'CreateFileW': (HANDLE, [C.c_wchar_p, DWORD, DWORD, C.c_void_p, DWORD, DWORD, HANDLE]),
'GetFileInformationByHandle': (BOOL, [HANDLE, C.c_void_p]),
'GetFileInformationByHandleEx': (BOOL, [HANDLE, C.c_int, C.c_void_p, DWORD]),
+ 'SetStdHandle': (BOOL, [DWORD, HANDLE]),
}
for name, (result, arguments) in declarations.items():
function = getattr(lib, name)
@@ -53,6 +54,26 @@ def checked(value):
return value
+def private_stdin(encoding='utf-8'):
+ """Read the parent's pipe through a private handle; standard input becomes NUL.
+
+ A thread blocked reading the standard-input pipe stalls DLL loads on the
+ main thread: importing numpy (its OpenBLAS) queries the standard handles
+ and waits until the parent writes again. A private duplicate keeps those
+ queries away from the pending read.
+ """
+ import msvcrt
+ import sys
+ private = os.dup(sys.stdin.fileno())
+ null = os.open(os.devnull, os.O_RDONLY)
+ try:
+ os.dup2(null, 0)
+ finally:
+ os.close(null)
+ checked(kernel32().SetStdHandle(DWORD(-10 & 0xffffffff), msvcrt.get_osfhandle(0))) # STD_INPUT_HANDLE
+ return open(private, encoding=encoding, errors=sys.stdin.errors)
+
+
def process_exited(pid):
"""True/False/None for exited/running/uninspectable, without waiting.