Skip to content

Instantly share code, notes, and snippets.

@timogoebel
Created August 18, 2017 09:42
Show Gist options
  • Save timogoebel/baf4cb2e43358c6df5a2f51b226407e7 to your computer and use it in GitHub Desktop.
Save timogoebel/baf4cb2e43358c6df5a2f51b226407e7 to your computer and use it in GitHub Desktop.
GFS2 filelock test
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