Spaces:
Running
Running
fix: replace assert with RuntimeError guard, truncate stderr before decode
Browse files- Replace assert in _worker with explicit RuntimeError guard (assert
strips in optimized mode, RuntimeError always fires)
- Truncate stderr to 2000 bytes before decoding in _run_demucs to
prevent unbounded error messages
- Add explanatory comment in test mock clarifying why htdemucs path
is used and that production code is model-agnostic via rglob()
- processor.py +3 -2
- tests/test_processor.py +2 -0
processor.py
CHANGED
|
@@ -62,7 +62,7 @@ async def _run_demucs(job_id: str, input_path: str, output_path: str) -> None:
|
|
| 62 |
_jobs[job_id].progress = 80
|
| 63 |
|
| 64 |
if proc.returncode != 0:
|
| 65 |
-
raise RuntimeError(f"Demucs failed: {stderr.decode(errors='replace')}")
|
| 66 |
|
| 67 |
no_vocals = next(demucs_work_dir.rglob("no_vocals.mp3"), None)
|
| 68 |
if no_vocals is None:
|
|
@@ -82,7 +82,8 @@ async def _run_demucs(job_id: str, input_path: str, output_path: str) -> None:
|
|
| 82 |
|
| 83 |
async def _worker() -> None:
|
| 84 |
"""Background worker that pulls jobs from the queue and runs Demucs."""
|
| 85 |
-
|
|
|
|
| 86 |
while True:
|
| 87 |
job_id, input_path, output_path = await _queue.get()
|
| 88 |
try:
|
|
|
|
| 62 |
_jobs[job_id].progress = 80
|
| 63 |
|
| 64 |
if proc.returncode != 0:
|
| 65 |
+
raise RuntimeError(f"Demucs failed: {stderr[:2000].decode(errors='replace')}")
|
| 66 |
|
| 67 |
no_vocals = next(demucs_work_dir.rglob("no_vocals.mp3"), None)
|
| 68 |
if no_vocals is None:
|
|
|
|
| 82 |
|
| 83 |
async def _worker() -> None:
|
| 84 |
"""Background worker that pulls jobs from the queue and runs Demucs."""
|
| 85 |
+
if _queue is None:
|
| 86 |
+
raise RuntimeError("Queue not initialized before worker started")
|
| 87 |
while True:
|
| 88 |
job_id, input_path, output_path = await _queue.get()
|
| 89 |
try:
|
tests/test_processor.py
CHANGED
|
@@ -23,6 +23,8 @@ async def test_run_demucs_updates_state_on_success(tmp_path, monkeypatch):
|
|
| 23 |
async def communicate(self):
|
| 24 |
# Simulate Demucs writing output file
|
| 25 |
demucs_work_dir = output_path.parent / f"demucs_{job_id}"
|
|
|
|
|
|
|
| 26 |
out_file = demucs_work_dir / "htdemucs" / "input" / "no_vocals.mp3"
|
| 27 |
out_file.parent.mkdir(parents=True, exist_ok=True)
|
| 28 |
out_file.write_bytes(b"\xff\xfb" + b"\x00" * 50)
|
|
|
|
| 23 |
async def communicate(self):
|
| 24 |
# Simulate Demucs writing output file
|
| 25 |
demucs_work_dir = output_path.parent / f"demucs_{job_id}"
|
| 26 |
+
# "htdemucs" is the default Demucs model name; production code uses rglob()
|
| 27 |
+
# to be model-agnostic — this path just needs to be under demucs_work_dir
|
| 28 |
out_file = demucs_work_dir / "htdemucs" / "input" / "no_vocals.mp3"
|
| 29 |
out_file.parent.mkdir(parents=True, exist_ok=True)
|
| 30 |
out_file.write_bytes(b"\xff\xfb" + b"\x00" * 50)
|