Compare commits

...
2 Commits
Author SHA1 Message Date
imSp4rky 35dbfa523c fix(api): serialize the job progress replace to stop Windows errno 13
Concurrent threads replacing the same progress file exhausted the retry budget on Windows. A module lock removes the in-process contention and the retry loop now raises on its last attempt.
2026-09-09 08:43:28 -06:00
imSp4rky 2971a3a7da fix(manifests): flag DASH audio using the standard description role 2026-09-08 21:31:46 -06:00
3 changed files with 58 additions and 9 deletions
+39
View File
@@ -0,0 +1,39 @@
import xml.etree.ElementTree as ET
import pytest
from unshackle.core.manifests.dash import DASH
def adaptation_set(scheme: str, value: str) -> ET.Element:
return ET.fromstring(f'<AdaptationSet><Accessibility schemeIdUri="{scheme}" value="{value}"/></AdaptationSet>')
@pytest.mark.parametrize(
"scheme,value",
[
# "description" is the value the DASH role scheme defines. Stan writes it, and reading only
# "descriptive" left every audio-description track unflagged.
("urn:mpeg:dash:role:2011", "description"),
("urn:mpeg:dash:role:2011", "descriptive"),
("urn:tva:metadata:cs:AudioPurposeCS:2007", "1"),
],
)
def test_descriptive_accessibility_values(scheme: str, value: str) -> None:
assert DASH.is_descriptive(adaptation_set(scheme, value)) is True
@pytest.mark.parametrize(
"scheme,value",
[
("urn:mpeg:dash:role:2011", "main"),
("urn:mpeg:dash:role:2011", "caption"),
("urn:tva:metadata:cs:AudioPurposeCS:2007", "2"),
],
)
def test_non_descriptive_accessibility_values(scheme: str, value: str) -> None:
assert DASH.is_descriptive(adaptation_set(scheme, value)) is False
def test_no_accessibility_element() -> None:
assert DASH.is_descriptive(ET.fromstring("<AdaptationSet/>")) is False
+14 -8
View File
@@ -23,25 +23,31 @@ def read_payload(path: Path) -> Dict[str, Any]:
return json.load(handle)
_replace_lock = threading.Lock()
def write_result(path: Path, payload: Dict[str, Any]) -> None:
"""Write the payload with an atomic replace, because the parent polls this file during the write.
Each call gets its own temp name, so two threads writing this destination cannot replace away
the temp file the other is about to move.
Windows denies the replace while the parent holds the destination open, so retry with a backoff.
Windows denies the replace while another thread or the parent holds the destination open. The
lock removes the in-process contention; the retry covers the parent process.
"""
path.parent.mkdir(parents=True, exist_ok=True)
tmp = path.with_name(f"{path.name}.{uuid4().hex}.tmp")
try:
tmp.write_text(json.dumps(payload), encoding="utf-8")
for attempt in range(5):
try:
os.replace(tmp, path)
return
except PermissionError:
time.sleep(0.02 * (attempt + 1))
os.replace(tmp, path)
with _replace_lock:
for attempt in range(10):
try:
os.replace(tmp, path)
return
except PermissionError:
if attempt == 9:
raise
time.sleep(0.02 * (attempt + 1))
except OSError:
tmp.unlink(missing_ok=True)
raise
+5 -1
View File
@@ -1111,7 +1111,11 @@ class DASH:
"""Whether the Adaptation Set is Descriptive."""
return any(
(x.get("schemeIdUri"), x.get("value"))
in (("urn:mpeg:dash:role:2011", "descriptive"), ("urn:tva:metadata:cs:AudioPurposeCS:2007", "1"))
in (
("urn:mpeg:dash:role:2011", "description"),
("urn:mpeg:dash:role:2011", "descriptive"),
("urn:tva:metadata:cs:AudioPurposeCS:2007", "1"),
)
for x in adaptation_set.findall("Accessibility")
)