runtraj.execution.inputs.lock#
- runtraj.execution.inputs.lock(url, name)[source]#
Hold a lock on the file name at url while the
withblock runs.Hold it around reading a file, changing it and writing it back, so a second program doing the same waits for the first instead of writing over its change. Each hour’s pod of a schedule holds it on
releases.csvwhile it copies the file (get()), adds its hours, and copies it back (put()).The lock is a small file
.<name>.locknext to name, made only if it is not there (open(..., "x"):If-None-Matchon S3,ifGenerationMatch=0on Google Cloud Storage,O_EXCLon a folder), and deleted at the end of the block. It says which host and process holds it. While the block runs, the holder rewrites it everyLOCK_REFRESH_SECONDS, so a long hold (a pod downloading the met) still looks alive. A program that finds it waits, and takes it over if it has not changed forLOCK_STALE_SECONDSby its own clock, so a holder that crashed does not stop every later one.- Parameters:
- Raises:
OSError – If the lock cannot be made or read, such as a refused connection or expired credentials.
- Return type:
Notes
A store that ignores
If-None-Match(some older S3-compatible ones) lets two programs make the lock at once, so it does not protect there. A holder that stops rewriting its lock forLOCK_STALE_SECONDS(a process paused that long) can be taken over; it then logs a warning when it finishes.Examples
>>> import fsspec >>> fs = fsspec.filesystem("memory") >>> with lock("memory://lock-example/project", "releases.csv"): ... fs.exists("/lock-example/project/.releases.csv.lock") True >>> fs.exists("/lock-example/project/.releases.csv.lock") False