https://github.com/inab/rwfilelock
Readers / writers file lock python helper class
https://github.com/inab/rwfilelock
library python
Last synced: 5 months ago
JSON representation
Readers / writers file lock python helper class
- Host: GitHub
- URL: https://github.com/inab/rwfilelock
- Owner: inab
- License: lgpl-2.1
- Created: 2020-02-16T17:04:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-06T19:47:38.000Z (almost 2 years ago)
- Last Synced: 2025-03-09T17:44:29.279Z (over 1 year ago)
- Topics: library, python
- Language: Python
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Readers / writers file lock Python helper class
[](https://github.com/inab/RWFileLock/actions/workflows/build_n_deploy.yml)
This library was created in order to ease the synchronization of several processes
using shared resources, like a caching directory or a SQLite database. All of them
can use the resources, but only one should update them.
The library is being used in several INB projects.
## Example of a shared lock using context:
```python
import datetime
import os
import time
from RWFileLock import RWFileLock
lock = RWFileLock("/tmp/rwfilelock.lock")
with lock.shared_lock():
print(
f"[{datetime.datetime.now().isoformat()}] Got shlock {os.getpid()}"
)
time.sleep(7)
print(
f"[{datetime.datetime.now().isoformat()}] Releasing shlock {os.getpid()}"
)
```