fix: dau_engine de quy spawn vo han + load rat cham (ban 1.1.2)
Trieu chung tu user: Task Manager day daw_engine process, port 8000->8005 leo thang, engine.log co engine moi moi ~2.5-3.3s trong nhieu phut. Goc re: app/core/vst_engine.py module-level: HAS_PEDALBOARD = check_pedalboard_safe() -> subprocess.run([sys.executable, '-c', 'import pedalboard'], timeout=2.0) Khi frozen, sys.executable = daw_engine.exe. PyInstaller bootloader bo qua '-c' va chay script nhung (desktop_engine.py = CA ENGINE) -> moi lan check thu vien lai khoi dong mot engine moi (timeout 2s moi check, block startup ~4s) -> engine con import app.main -> lai chay check -> spawn tiep => de quy vo han, hang chuc engine, may nghen, load 6-7.5s. Fix: - vst_engine: check_pedalboard_safe/check_pyfluidsynth_safe dung importlib.util.find_spec (micro-giay, khong spawn, hoat dong frozen). - desktop_engine.main(): guard phong thu - neu bi goi voi argv[1]=='-c' (dang bi dung nhu python interpreter) thi thoat ngay khong chay server. Verify tren Linux (engine frozen): - STARTUP: 6-7.5s -> 1.24-1.33s (3 lan lien tiep) - sau 15s: dung 1 engine, 0 process '-c import' (truoc: hang chuc) - 86 tests pass; test suite 34s -> 14s (may het bi spam).
This commit is contained in:
+19
-17
@@ -49,27 +49,29 @@ def render_midi_events_to_audio(midi_events: list, sr: int = 44100, bpm: float =
|
||||
out_r /= max_peak
|
||||
return np.vstack([out_l, out_r])
|
||||
|
||||
def check_pedalboard_safe():
|
||||
import subprocess, sys
|
||||
def _module_available(name: str) -> bool:
|
||||
"""Kiem tra module co san khong — KHONG spawn subprocess.
|
||||
|
||||
Truoc day dung subprocess.run([sys.executable, '-c', 'import X']) —
|
||||
khi app dong goi (PyInstaller frozen), sys.executable = daw_engine.exe
|
||||
-> subprocess chay CA ENGINE (bootloader bo qua '-c', chay desktop_engine)
|
||||
-> moi lan check lai sinh ra engine moi -> de quy spawn vo han
|
||||
(Task Manager day daw_engine, port 8000-8005 leo thang, load rat cham).
|
||||
find_spec() nhanh (micro-giay) va hoat dong ca source lan frozen.
|
||||
"""
|
||||
import importlib.util
|
||||
try:
|
||||
res = subprocess.run(
|
||||
[sys.executable, "-c", "import pedalboard"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=2.0
|
||||
)
|
||||
return res.returncode == 0
|
||||
except Exception:
|
||||
return importlib.util.find_spec(name) is not None
|
||||
except (ImportError, AttributeError, ValueError):
|
||||
return False
|
||||
|
||||
|
||||
def check_pedalboard_safe():
|
||||
return _module_available("pedalboard")
|
||||
|
||||
|
||||
def check_pyfluidsynth_safe():
|
||||
import subprocess, sys
|
||||
try:
|
||||
res = subprocess.run(
|
||||
[sys.executable, "-c", "import fluidsynth"],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=2.0
|
||||
)
|
||||
return res.returncode == 0
|
||||
except Exception:
|
||||
return False
|
||||
return _module_available("fluidsynth")
|
||||
|
||||
HAS_PEDALBOARD = check_pedalboard_safe()
|
||||
HAS_PYFLUIDSYNTH = check_pyfluidsynth_safe()
|
||||
|
||||
Reference in New Issue
Block a user