Skip to content

Commit

Permalink
Doc and cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsirois committed Sep 2, 2024
1 parent 5ff197e commit 3a94e45
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pex/cache/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,28 @@

_LOCK = None # type: Optional[Tuple[bool, int, str]]

_PEX_CACHE_ACCESS_LOCK_ENV_VAR = "_PEX_CACHE_ACCESS_LOCK"


def save_lock_state():
# type: () -> None
"""Records any current lock state in a manner that can survive un-importing of this module."""

# N.B.: This supports the sole case of a Pex PEX, whose runtime obtains a lock that it must hand
# off to the Pex CLI it spawns.

global _LOCK
if _LOCK is not None:
exclusive, lock_fd, lock_file = _LOCK
os.environ["_PEX_CACHE_ACCESS_LOCK"] = "|".join(
os.environ[_PEX_CACHE_ACCESS_LOCK_ENV_VAR] = "|".join(
(str(int(exclusive)), str(lock_fd), lock_file)
)


def _maybe_restore_lock_state():
# type: () -> None

saved_lock_state = os.environ.pop("_PEX_CACHE_ACCESS_LOCK", None)
saved_lock_state = os.environ.pop(_PEX_CACHE_ACCESS_LOCK_ENV_VAR, None)
if saved_lock_state:
encoded_exclusive, encoded_lock_fd, lock_file = saved_lock_state.split("|", 2)
global _LOCK
Expand Down

0 comments on commit 3a94e45

Please sign in to comment.