Skip to content

Instantly share code, notes, and snippets.

@oiuww09fn
Last active August 29, 2015 14:08
Show Gist options
  • Save oiuww09fn/d1f14224fd1854d90035 to your computer and use it in GitHub Desktop.
Save oiuww09fn/d1f14224fd1854d90035 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import fcntl
import sys
import time
def lockFile(f):
try:
fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
except IOError:
return False
return True
fp = open("/tmp/tmp.txt", 'w')
a = lockFile(fp)
if not a:
sys.exit(0)
else:
print("Locked the file...")
while 1:
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment