Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Update filelock.py #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions README.txt → README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@

========
FileLock
========
# About

A file locking mechanism that has context-manager support so
you can use it in a with statement. This should be relatively cross
compatible as it doesn't rely on msvcrt or fcntl for the locking.


Originally posted at http://www.evanfosmark.com/2009/01/cross-platform-file-locking-support-in-python/
# Usage
```python
from filelock import FileLock

with FileLock("myfile.txt.lock"):
print("Lock acquired.")
with open("myfile.txt"):
# work with the file as it is now locked
```
2 changes: 1 addition & 1 deletion filelock/filelock.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def acquire(self):
try:
self.fd = os.open(self.lockfile, os.O_CREAT|os.O_EXCL|os.O_RDWR)
self.is_locked = True #moved to ensure tag only when locked
break;
break
except OSError as e:
if e.errno != errno.EEXIST:
raise
Expand Down