c7c3a79028
test / image-input-builds (pull_request) Failing after 13m11s
test / unit (pull_request) Has started running
test / coverage (pull_request) Blocked by required conditions
test / integration-docker (pull_request) Blocked by required conditions
tracker-policy-pr / check-pr (pull_request) Successful in 13s
31 lines
721 B
Python
31 lines
721 B
Python
"""Serialize Firecracker run-directory creation with orphan cleanup."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import fcntl
|
|
from contextlib import contextmanager
|
|
from pathlib import Path
|
|
from typing import Generator
|
|
|
|
from . import util
|
|
|
|
|
|
def _lock_path() -> Path:
|
|
return util.cache_dir() / "run.lifecycle.lock"
|
|
|
|
|
|
@contextmanager
|
|
def hold() -> Generator[None]:
|
|
"""Exclude cleanup while a launch directory lacks a visible VMM."""
|
|
path = _lock_path()
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
with path.open("a", encoding="utf-8") as handle:
|
|
fcntl.flock(handle, fcntl.LOCK_EX)
|
|
try:
|
|
yield
|
|
finally:
|
|
fcntl.flock(handle, fcntl.LOCK_UN)
|
|
|
|
|
|
__all__ = ["hold"]
|