Skip to content

jplusplus/lockfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A minimal, no-dependencies lock file mechanism, creating a temporary file to signal that a specific file should not be touched by other scripts, or instances of the same script.

Created for Europe 1° Warmer.

This is module does not implement OS level file locking. For that, see e.g. the built-in lockfile module, zc.lockfile, or other similar projects.

Installation

pip install tmplockfile

Usage

from tmplockfile import LockFile, ResourceLocked

with LockFile("data.csv") as lockfile:
    # Do things involving data.csv here
    #
    # A lock-file is temporarily placed in the same directory,
    # in a way that avoids the most obvious race conditions.
    # The variable `lockfile` contains the name of the lock-file,
    # e.g. `data.csv~lock`.

except ResourceLocked:
    print("Another script is currently working on data.csv. Try again later!")

Changelog

  • 0.0.3

    • Don't crash when no lockfile could be created

About

A minimal lock file mechanism

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages