Answer prose round 1: 0 🔴, 4 🟡 (0 misread); reword HELD, Refused, heavy_slot, ensure_image and the past-the-documents refusal
CI / tests (pull_request) Successful in 2m4s
CI / tests (pull_request) Successful in 2m4s
This commit is contained in:
@@ -41,7 +41,7 @@ Slot = typing.Callable[[], typing.ContextManager[Failure | None]]
|
|||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class Refused:
|
class Refused:
|
||||||
"""adf-codec refused the document at index of those handed to adfs_to_markdown."""
|
"""Why adf-codec refused one of the documents handed to adfs_to_markdown, and that document's index among them."""
|
||||||
index: int
|
index: int
|
||||||
failure: Failure
|
failure: Failure
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ def docker(args: list[str], text: str, seconds: int, call: typing.Callable[...,
|
|||||||
|
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def heavy_slot(env: typing.Mapping[str, str] = os.environ, slots: int | None = None) -> typing.Iterator[Failure | None]:
|
def heavy_slot(env: typing.Mapping[str, str] = os.environ, slots: int | None = None) -> typing.Iterator[Failure | None]:
|
||||||
"""Holds one of the machine's heavy slots, which run-heavy shares, for the with block; under run-heavy the process already holds one, so it waits for none."""
|
"""Holds one of the machine's heavy slots, which run-heavy shares, for the with block. Under run-heavy the process already holds one, so it doesn't wait."""
|
||||||
if HELD in env:
|
if HELD in env:
|
||||||
yield None
|
yield None
|
||||||
return
|
return
|
||||||
@@ -78,7 +78,7 @@ def heavy_slot(env: typing.Mapping[str, str] = os.environ, slots: int | None = N
|
|||||||
count = slot_count(usable_cpus()) if slots is None else slots
|
count = slot_count(usable_cpus()) if slots is None else slots
|
||||||
try:
|
try:
|
||||||
folder.mkdir(parents=True, exist_ok=True)
|
folder.mkdir(parents=True, exist_ok=True)
|
||||||
_, fd = waited_slot(folder, count, lambda: print(f"adf-codec: waiting for a heavy slot, of {count} on this machine, to build the shim's image", file=sys.stderr, flush=True))
|
_, fd = waited_slot(folder, count, lambda: print(f"adf-codec: waiting for a heavy slot, of {count} on this machine, in {folder}, to build the shim's image; `fuser {folder}/slot-*` names the processes that hold them", file=sys.stderr, flush=True))
|
||||||
except OSError as failure:
|
except OSError as failure:
|
||||||
yield Failure(f"cannot take a heavy slot in {folder}: {failure.strerror}")
|
yield Failure(f"cannot take a heavy slot in {folder}: {failure.strerror}")
|
||||||
return
|
return
|
||||||
@@ -91,7 +91,7 @@ def heavy_slot(env: typing.Mapping[str, str] = os.environ, slots: int | None = N
|
|||||||
def ensure_image(shim: pathlib.Path, run_docker: Docker = docker, slot: Slot = heavy_slot) -> str | Failure:
|
def ensure_image(shim: pathlib.Path, run_docker: Docker = docker, slot: Slot = heavy_slot) -> str | Failure:
|
||||||
"""The tag of the image for the shim folder, built from that folder first where this machine has no image under that tag.
|
"""The tag of the image for the shim folder, built from that folder first where this machine has no image under that tag.
|
||||||
|
|
||||||
The build waits for a heavy slot, since `docker build` is heavy. Once the slot is held it looks again, as another process may have built the image meanwhile."""
|
The build waits for a heavy slot. Once this process holds the slot, it inspects again, as another process may have built the image meanwhile."""
|
||||||
tag = image_tag(shim)
|
tag = image_tag(shim)
|
||||||
found = image_found(tag, run_docker)
|
found = image_found(tag, run_docker)
|
||||||
if found is not False:
|
if found is not False:
|
||||||
@@ -169,7 +169,7 @@ def adfs_to_markdown(documents: list[dict[str, typing.Any]], run: Run = containe
|
|||||||
return []
|
return []
|
||||||
out = answer("to-markdown", json.dumps(documents), run)
|
out = answer("to-markdown", json.dumps(documents), run)
|
||||||
if isinstance(out, Refused) and not 0 <= out.index < len(documents):
|
if isinstance(out, Refused) and not 0 <= out.index < len(documents):
|
||||||
return Failure(f"the adf-codec shim refused document {out.index} of the {len(documents)} handed to it, counting from 0")
|
return Failure(f"the adf-codec shim refused a document at index {out.index}, past the {len(documents)} it was handed")
|
||||||
if isinstance(out, Refused | Failure):
|
if isinstance(out, Refused | Failure):
|
||||||
return out
|
return out
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import typing
|
|||||||
CPUS_PER_SLOT = 4
|
CPUS_PER_SLOT = 4
|
||||||
# Seconds between tries while every slot is held; a slot frees as its command exits.
|
# Seconds between tries while every slot is held; a slot frees as its command exits.
|
||||||
POLL_SECONDS = 1
|
POLL_SECONDS = 1
|
||||||
# The environment variable that tells a process it already holds a slot, which run-heavy sets for its command, so a step of a gate it runs doesn't wait on the gate's own slot.
|
# Names the environment variable run-heavy sets for the command it runs. A process that finds it set already holds a slot, and takes no second one.
|
||||||
HELD = "RUN_HEAVY_SLOT"
|
HELD = "RUN_HEAVY_SLOT"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user