Giter Site home page Giter Site logo

jonasrauber / lockfile Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 9 KB

lockfile provides a minimalistic and modern implementation of a simple file-based lock mechanism for Python

Python 100.00%
python filelock lockfile lock multiprocessing python3

lockfile's Introduction

image

lockfile

๐Ÿ”ฅ Why lockfile

lockfile provides a minimalistic and modern implementation of a simple file-based lock mechanism for Python.

  • Minimalistic: lockfile does one thing, and one thing only
  • Modern: lockfile supports pathlib.Path objects
  • Type annotated: lockfile provides comprehensive type annotations
  • Convinient: lockfile automatically appendx a .lock suffix if needed
  • Clean: all code is formatted with Black and checked with MyPy and flake8

There are a number of alternatives such as py-filelock and FileLock that actually inspired this project but are more complex and somewhat outdated.

๐Ÿ“– Documentation

Just look at this README and the code, it's really simple.

๐Ÿš€ Quickstart

No installation, just copy lockfile.py to your project. It has zero dependencies beyond Python 3.6 or newer.

If you think an installable package might be useful, just open an issue.

๐ŸŽ‰ Example

You can safely run the following code in two separate processes:

from pathlib import Path
from lockfile import Lock

path = Path("example.txt")
with Lock(path):
    # Note: you don't need to use the lock to write to that specific file,
    # it can be used for anything

    with open(path, "w") as f:
        f.write("Hello!")

๐Ÿ—บ Use cases

Whenever you need a simple, file-based locking mechanism in Python, for example when you want to write to the same file from different processes, possibly even from different machines using a shared file system (Note: NFS will usually not provide the necessary guarantees, but there are other shared (cluster) file systems that do).

๐Ÿ Compatibility

Python 3.6 and newer

lockfile's People

Contributors

jonasrauber avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

lockfile's Issues

Licence

This small humble project don't seems to be actively maintained, can I include your main file as a snippet in a commercial project?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.