Created
November 7, 2018 06:21
-
-
Save clungzta/09e7155225636e244f60291369e6ce4c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import time | |
| from lockfile import LockFile, LockTimeout | |
| filepath = '/home/alex/Downloads/blah.txt' | |
| lock = LockFile(filepath) | |
| if lock.is_locked(): | |
| print('Waiting to acquire the file lock...') | |
| lock.acquire(timeout=10) | |
| with open(filepath, 'w') as f: | |
| print('Acquired the file lock, now writing!') | |
| f.writelines(['{}'.format(time.time())]) | |
| print('sleeping to simulate a slow file operation...') | |
| time.sleep(10) | |
| print("Successfully updated the file, unlocking...") | |
| lock.release() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment