Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1.     def check_posix_lock(filename):
  2.         ''' check if POSIX lock (fcntl/lockf) is held on filename '''
  3.         lockfile = None
  4.         try:
  5.             lockfile = open(filename, 'w')
  6.             fcntl.lockf(lockfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
  7.         except BlockingIOError:
  8.             return True
  9.         except:
  10.             pass
  11.         finally:
  12.             if lockfile:
  13.                 lockfile.close()
  14.         return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement