Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jonasrauber/lockfile
lockfile provides a minimalistic and modern implementation of a simple file-based lock mechanism for Python
https://github.com/jonasrauber/lockfile
filelock lock lockfile multiprocessing python python3
Last synced: 21 days ago
JSON representation
lockfile provides a minimalistic and modern implementation of a simple file-based lock mechanism for Python
- Host: GitHub
- URL: https://github.com/jonasrauber/lockfile
- Owner: jonasrauber
- Created: 2020-05-12T08:56:37.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-12T09:54:32.000Z (over 4 years ago)
- Last Synced: 2024-10-29T13:55:43.022Z (2 months ago)
- Topics: filelock, lock, lockfile, multiprocessing, python, python3
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/ambv/black======================================================================================
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:
.. code-block:: python
from pathlib import Path
from lockfile import Lockpath = 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 anythingwith 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