nemo_gym.utils.install_lock
nemo_gym.utils.install_lock
Share one local tool installation among the worker processes of a server.
With num_workers > 1, each uvicorn worker installs a missing tool on its own first call,
and the workers’ first calls can arrive together.
Without coordination they would download, unpack and npm install into the same directory at once.
An installer takes install_lock around its work,
so one worker installs while the others wait and then reuse that install.
An install records where it put the tool only after it finished, with record_install,
so an interrupted install is never mistaken for a complete one.
Module Contents
Functions
API
Put a recorded install’s directory first on PATH when it still holds executable.
Another worker may have installed the tool into a directory that is not on this process’s PATH.
Returns False when there is no record or the recorded directory no longer holds the executable.
install_lock for a coroutine, which waits without blocking the event loop.
It polls instead of waiting in a thread, so a cancelled waiter leaves no thread behind that could take the lock later.
Hold an exclusive lock on lock_path across processes until the block exits.
The lock file must live outside any directory the install may remove, because a lock on a removed file no longer excludes a process that opens the path again.
Record that an install finished and put its executables in bin_dir.
The marker is replaced atomically, so a reader sees either no record or a complete one.