Files
bot-bottle/bot_bottle/backend/firecracker/lifecycle_lock.py
T
didericis-codex 3bc618c264
test / unit (pull_request) Successful in 1m5s
test / coverage (pull_request) Has been skipped
test / integration-docker (pull_request) Has been cancelled
test / image-input-builds (pull_request) Successful in 1m10s
tracker-policy-pr / check-pr (pull_request) Failing after 12m1s
fix(cleanup): revalidate destructive backend plans
2026-07-27 04:16:56 +00:00

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"]