Created
August 18, 2017 09:42
-
-
Save timogoebel/baf4cb2e43358c6df5a2f51b226407e7 to your computer and use it in GitHub Desktop.
GFS2 filelock test
This file contains 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 | |
import fcntl, struct | |
lockfile = open('/media/test/lockfile', 'w') | |
lockdata = struct.pack('hhllhh', fcntl.F_WRLCK, 0, 0, 0, 0, 0) | |
while 1: | |
try: | |
fcntl.fcntl(lockfile.fileno(), fcntl.F_SETLK, lockdata) | |
print "I have the lock." | |
time.sleep(1) | |
except KeyboardInterrupt: | |
print('interrupted!') | |
break | |
except: | |
print "Lock aquisition failed." | |
time.sleep(1) | |
lockfile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment