Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

fix(runio): on Windows a lock holder's pid is judged without a console signal — os.kill(pid, 0) there is CTRL_C_EVENT: GenerateConsoleCtrlEvent sends a Ctrl+C to the processes on the caller's console (pid 0 every time, another live pid on it late), and an ended holder's pid raises WinError 87 out of acquire_run_dir_lock instead of being reclaimed; _pid_alive opens the process for SYNCHRONIZE only and waits zero time: no such pid is dead, a process it may not open (System, another user's) is alive, an ended one is dead; POSIX keeps signal 0; run-contract §7 says how a holder is asked after

Soohong Kim10e682c24a41
diff --git a/docs/run-contract.md b/docs/run-contract.md
index 7c0ccf6..d823c3e 100644
--- a/docs/run-contract.md
+++ b/docs/run-contract.md
@@ -569,7 +569,11 @@ boundary of the run-dir's atomicity and concurrency guarantees. What is **in for
it — same device, inode and content, and `release_run_dir_lock` withdraws that lock's exit
cleanup — while making, reclaiming and removing the entry queue on a kernel lock on the run dir
itself, so among sprite-gen processes on one host, on a file system that locks folders, neither a
- released writer's exit nor a late reclaimer removes a lock another writer took meanwhile. Removing
+ released writer's exit nor a late reclaimer removes a lock another writer took meanwhile. A lock that
+ names its holder's pid is reclaimed only when that process has ended on this host, asked without
+ sending it anything: signal 0 on POSIX; on Windows, where `os.kill(pid, 0)` is `CTRL_C_EVENT` — a Ctrl+C to the
+ console — the process is opened only to see whether it has ended, and one that cannot be opened (a
+ system or another user's process) counts as alive, never as dead. Removing
and holding belong to the process that made the entry: a hold is bound to the pid that took it, so a
forked child never re-enters, releases or removes its parent's lock and is refused by it like any
other writer. Where `os.register_at_fork` exists, a child forgets its parent's holds and exit
diff --git a/sprite_gen/spec/runio.py b/sprite_gen/spec/runio.py
index 23c96a3..79b3fbc 100644
--- a/sprite_gen/spec/runio.py
+++ b/sprite_gen/spec/runio.py
@@ -124,6 +124,12 @@ if fcntl is None and os.name == "nt": # pragma: no cover - Windows-only backend
_CloseHandle.restype = wintypes.BOOL
_CloseHandle.argtypes = [wintypes.HANDLE]
_WAIT_INFINITE, _WAIT_OWNED = 0xFFFFFFFF, (0x00000000, 0x00000080) # WAIT_OBJECT_0, WAIT_ABANDONED
+ # 락 주인이 살았는지(`_pid_alive`)는 그 프로세스를 SYNCHRONIZE 로 열어 끝났는지 기다리지 않고 본다 — 신호를 보내지 않는다
+ _OpenProcess = _kernel32.OpenProcess
+ _OpenProcess.restype = wintypes.HANDLE
+ _OpenProcess.argtypes = [wintypes.DWORD, wintypes.BOOL, wintypes.DWORD]
+ _SYNCHRONIZE, _WAIT_SIGNALED, _WAIT_TIMEOUT = 0x00100000, 0x00000000, 0x00000102
+ _ERROR_ACCESS_DENIED, _ERROR_INVALID_PARAMETER = 5, 87
_LOCK_IMPL = "LockFileEx"
except (ImportError, OSError, AttributeError):
_LOCK_IMPL = None
@@ -333,6 +339,31 @@ def new_stage(out: Path, suffix: str) -> Path:
def _pid_alive(pid: int) -> bool:
+ """락 주인 `pid` 가 이 호스트에 살아 있나 — 그 프로세스에 아무것도 보내지 않고 본다. 있는지 알 수 없는 것을 죽었다고 읽지
+ 않는다(거짓 '죽음'은 산 writer 의 락을 거둔다). POSIX 는 신호 0: 보내지 않고 찾기와 권한만 보며, 남의 프로세스(EPERM)는 살아
+ 있다. Windows 의 os.kill 은 신호 0 을 CTRL_C_EVENT 로 GenerateConsoleCtrlEvent 에 넘긴다 — 같은 콘솔의 프로세스들에
+ Ctrl+C 가 가고(pid 0 이면 늘, 같은 콘솔의 다른 산 pid 면 늦게라도), 끝난 pid 에는 답 대신 OSError(WinError 87) 다. 그래서
+ 쓰지 않고, 그 프로세스를 SYNCHRONIZE 로만 열어 끝났는지(신호 상태) 기다리지 않고 본다 — 없는 pid 는 열리지 않고
+ (ERROR_INVALID_PARAMETER) 죽은 것, 열 권한이 없는 것(시스템·남의 프로세스, ERROR_ACCESS_DENIED)은 살아 있는 것, 끝났지만
+ 핸들이 남은 프로세스는 열려도 신호 상태라 죽은 것이다(docs/run-contract.md §7)."""
+ if os.name == "nt": # pragma: no cover - Windows-only backend
+ if not 0 < pid <= 0xFFFFFFFF: # Windows pid 는 DWORD 이고 0 은 유휴 프로세스다 — ctypes 는 그 밖의 값을 잘라 다른 pid 로 넘긴다
+ return False
+ handle = _OpenProcess(_SYNCHRONIZE, False, pid)
+ if not handle:
+ error = ctypes.get_last_error()
+ if error == _ERROR_INVALID_PARAMETER:
+ return False
+ if error == _ERROR_ACCESS_DENIED:
+ return True
+ raise ctypes.WinError(error)
+ try:
+ state = _WaitForSingleObject(handle, 0)
+ if state not in (_WAIT_SIGNALED, _WAIT_TIMEOUT):
+ raise ctypes.WinError(ctypes.get_last_error())
+ return state == _WAIT_TIMEOUT
+ finally:
+ _CloseHandle(handle)
try:
os.kill(pid, 0)
except ProcessLookupError: