Skip to content

Commit 20f37d8

Browse files
committed
Add readme
Signed-off-by: Bernát Gábor <[email protected]>
1 parent 676d62f commit 20f37d8

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

.readthedocs.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 2
2+
build:
3+
image: latest
4+
formats:
5+
- htmlzip
6+
python:
7+
version: 3.8
8+
install:
9+
- method: pip
10+
path: .
11+
extra_requirements:
12+
- docs
13+
sphinx:
14+
builder: html
15+
configuration: docs/conf.py

README.md

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,59 @@ black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://gith
1010
[![Downloads](https://pepy.tech/badge/filelock/month)](https://pepy.tech/project/filelock/month)
1111
[![check](https://github.com/tox-dev/py-filelock/actions/workflows/check.yml/badge.svg)](https://github.com/tox-dev/py-filelock/actions/workflows/check.yml)
1212

13-
This package contains a single module, which implements a platform independent
14-
file lock in Python, which provides a simple way of inter-process communication:
13+
This package contains a single module, which implements a platform independent file lock in Python, which provides a
14+
simple way of inter-process communication:
1515

1616
```Python
17-
from src.filelock import Timeout, FileLock
17+
from filelock import Timeout, FileLock
1818

1919
lock = FileLock("high_ground.txt.lock")
2020
with lock:
2121
open("high_ground.txt", "a").write("You were the chosen one.")
2222
```
2323

24-
**Don't use** a *FileLock* to lock the file you want to write to, instead create
25-
a separate *.lock* file as shown above.
24+
**Don't use** a _FileLock_ to lock the file you want to write to, instead create a separate _.lock_ file as shown above.
2625

2726
![animated example](https://raw.githubusercontent.com/tox-dev/py-filelock/main/example/example.gif)
2827

29-
3028
## Similar libraries
3129

32-
Perhaps you are looking for something like
33-
34-
* https://pypi.python.org/pypi/pid/2.1.1
35-
* https://docs.python.org/3.6/library/msvcrt.html#msvcrt.locking
36-
* or https://docs.python.org/3/library/fcntl.html#fcntl.flock
30+
Perhaps you are looking for something like:
3731

32+
- the [pid](https://pypi.python.org/pypi/pid) 3rd party library,
33+
- for Windows the [msvcrt](https://docs.python.org/3/library/msvcrt.html#msvcrt.locking) module in the standar library,
34+
- for UNIX the [fcntl](https://docs.python.org/3/library/fcntl.html#fcntl.flock) module in the standard library.
3835

3936
## Installation
4037

41-
*py-filelock* is available via PyPi:
38+
_py-filelock_ is available via PyPi:
4239

43-
```
44-
$ pip3 install filelock
40+
```bash
41+
python -m pip install filelock
4542
```
4643

47-
4844
## Documentation
4945

50-
The documentation for the API is available on
51-
[readthedocs.org](https://filelock.readthedocs.io/).
52-
46+
The documentation for the API is available on [readthedocs.org](https://filelock.readthedocs.io/).
5347

5448
### Examples
5549

56-
A *FileLock* is used to indicate another process of your application that a
57-
resource or working
58-
directory is currently used. To do so, create a *FileLock* first:
50+
A _FileLock_ is used to indicate another process of your application that a resource or working directory is currently
51+
used. To do so, create a _FileLock_ first:
5952

60-
```Python
61-
from src.filelock import Timeout, FileLock
53+
```python
54+
from filelock import Timeout, FileLock
6255

6356
file_path = "high_ground.txt"
6457
lock_path = "high_ground.txt.lock"
6558

6659
lock = FileLock(lock_path, timeout=1)
6760
```
6861

69-
The lock object supports multiple ways for acquiring the lock, including the
70-
ones used to acquire standard Python thread locks:
62+
The lock object supports multiple ways for acquiring the lock, including the ones used to acquire standard Python thread
63+
locks:
7164

72-
```Python
65+
```python
7366
with lock:
7467
open(file_path, "a").write("Hello there!")
7568

@@ -80,21 +73,20 @@ finally:
8073
lock.release()
8174
```
8275

83-
The *acquire()* method accepts also a *timeout* parameter. If the lock cannot be
84-
acquired within *timeout* seconds, a *Timeout* exception is raised:
76+
The _acquire()_ method accepts also a _timeout_ parameter. If the lock cannot be acquired within _timeout_ seconds, a
77+
_Timeout_ exception is raised:
8578

86-
```Python
79+
```python
8780
try:
8881
with lock.acquire(timeout=10):
8982
open(file_path, "a").write("I have a bad feeling about this.")
9083
except Timeout:
9184
print("Another instance of this application currently holds the lock.")
9285
```
9386

94-
The lock objects are recursive locks, which means that once acquired, they will
95-
not block on successive lock requests:
87+
The lock objects are recursive locks, which means that once acquired, they will not block on successive lock requests:
9688

97-
```Python
89+
```python
9890
def cite1():
9991
with lock:
10092
open(file_path, "a").write("I hate it when he does that.")
@@ -111,31 +103,24 @@ with lock:
111103
# And released here.
112104
```
113105

114-
All log messages by this library are made using the *DEBUG* level, under the
115-
`filelock` name. On how to control displaying/hiding that please consult the
106+
All log messages by this library are made using the _DEBUG_ level, under the `filelock` name. On how to control
107+
displaying/hiding that please consult the
116108
[logging documentation of the standard library](https://docs.python.org/3/howto/logging.html).
117109

118-
E.g. to hide these messages you can use
119-
`logging.getLogger("filelock").setLevel(logging.INFO)`.
120-
110+
E.g. to hide these messages you can use `logging.getLogger("filelock").setLevel(logging.INFO)`.
121111

122112
## FileLock vs SoftFileLock
123113

124-
The *FileLock* is platform dependent while the *SoftFileLock* is not. Use the
125-
*FileLock* if all instances of your application are running on the same host and
126-
a *SoftFileLock* otherwise.
127-
128-
The *SoftFileLock* only watches the existence of the lock file. This makes it
129-
ultra portable, but also more prone to dead locks if the application crashes.
130-
You can simply delete the lock file in such cases.
114+
The _FileLock_ is platform dependent while the _SoftFileLock_ is not. Use the _FileLock_ if all instances of your
115+
application are running on the same host and a _SoftFileLock_ otherwise.
131116

117+
The _SoftFileLock_ only watches the existence of the lock file. This makes it ultra portable, but also more prone to
118+
dead locks if the application crashes. You can simply delete the lock file in such cases.
132119

133120
## Contributions
134121

135-
Contributions are always welcome, please make sure they pass all tests before
136-
creating a pull request. Never hesitate to open a new issue, although it may
137-
take some time for me to respond.
138-
122+
Contributions are always welcome, please make sure they pass all tests before creating a pull request. Never hesitate to
123+
open a new issue, although it may take some time for me to respond.
139124

140125
## License
141126

0 commit comments

Comments
 (0)