diff --git a/README.txt b/README.md similarity index 61% rename from README.txt rename to README.md index b8d9718..6dac3ae 100644 --- a/README.txt +++ b/README.md @@ -1,7 +1,4 @@ - -======== -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 @@ -9,3 +6,12 @@ FileLock 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 +``` diff --git a/filelock/filelock.py b/filelock/filelock.py index d0e5d8d..337b97c 100755 --- a/filelock/filelock.py +++ b/filelock/filelock.py @@ -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