37 '''Acquire a lock, returning self if successful, False otherwise'''
41 print(
'Previous lock detected: %s' % self.
pddr(lock))
44 fd = os.open(self.
path, os.O_RDWR | os.O_CREAT, 0o777)
45 fh = os.fdopen(fd,
'r+')
49 fcntlflag = fcntl.LOCK_EX
51 fcntlflag |= fcntl.LOCK_NB
52 fcntl.lockf(fh, fcntlflag)
55 print(
'Unable to acquire lock on %s: existing lock %s' % (self.
path, fh.read()))
63 modtime = os.stat(self.
path)
64 outstring =
'Acquired lock: '+ self.
fddr() +
' at time '+ time.ctime(modtime.st_mtime)
66 except Exception
as e:
67 if os.path.isfile(self.
path):
75 'Error acquiring lock: %s, reason %s' % (self.
fddr(), e))