Answer principles round 1: 0 🔴, 3 🟡 (0 misread); state listed's lock, let each module drop its own ended files, test run_loop's listing end to end

This commit is contained in:
2026-10-29 20:33:52 +01:00
parent 9f71b9aa91
commit 326866e85b
9 changed files with 79 additions and 33 deletions
+13 -1
View File
@@ -18,7 +18,7 @@ def lock_file(folder: pathlib.Path, session: str) -> pathlib.Path:
@contextlib.contextmanager
def held(folder: pathlib.Path, session: str) -> typing.Iterator[Failure | None]:
"""Holds the session's lock while the with block runs, or yields a Failure where it cannot. loop-inbox's drop_ended takes the lock for a moment on each session whose files are still on disk, so a loop may find it held."""
"""Holds the session's lock while the with block runs, or yields a Failure where it cannot. loop-inbox takes the lock for a moment through ended, on each session whose files are still on disk, so a loop may find it held."""
path = lock_file(folder, session)
try:
make_private(folder)
@@ -42,6 +42,18 @@ def held(folder: pathlib.Path, session: str) -> typing.Iterator[Failure | None]:
yield None
def ended(folder: pathlib.Path, pattern: str) -> typing.Iterator[str]:
"""Each session with a file in folder that matches pattern, such as "*.json", and whose lock no loop holds. It yields each while holding that lock, so a loop that starts meanwhile keeps its files."""
try:
sessions = {path.stem for path in folder.glob(pattern)}
except OSError:
return
for session in sessions:
with held(folder, session) as unlocked:
if not unlocked:
yield session
def running(folder: pathlib.Path, session: str) -> bool:
"""Whether a loop holds the session's lock; False also where the lock file cannot be opened or locked."""
try: