Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jinmingyi1998/ezfilelock
a simple cross platform file lock
https://github.com/jinmingyi1998/ezfilelock
Last synced: about 2 months ago
JSON representation
a simple cross platform file lock
- Host: GitHub
- URL: https://github.com/jinmingyi1998/ezfilelock
- Owner: jinmingyi1998
- License: mit
- Created: 2022-11-10T09:02:39.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-10T09:37:14.000Z (about 2 years ago)
- Last Synced: 2024-10-29T04:16:51.480Z (about 2 months ago)
- Language: Python
- Size: 5.86 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# EZ File Lock
> A simple cross-platform File Lock## Quick start:
```shell
pip install ezfilelock
```
## Usage### Use just like builtin method open()
```python
from ezfilelock import openwith open('xxx.txt','r') as f:
print(f.read())
```### Use FileLock instance
```python
from ezfilelock import FileLock
from builtin import openwith FileLock('xxx.txt'):
# do continuous things with lock
with open('xxx.txt','w') as f:
f.write('hello')
with open('xxx.txt','a') as f:
f.write('world!')
with open('xxx.txt','r') as f:
f.read()
```### Read Write Lock
> Cannot Write when Reading.
>
> Cannot Read when Writing.
>
> Can Read by multiple threads at the same time```python
from ezfilelock import rwopenwith rwopen('xxx.txt',mode='w') as f:
f.write('hello world')with rwopen('xxx.txt',mode='r') as f:
print(f.read())
```