10 elif os.name ==
'posix':
12 LOCK_EX = fcntl.F_WRLCK
13 LOCK_SH = fcntl.F_RDLCK
14 LOCK_NB = fcntl.F_UNLCK
16 raise RuntimeError(
"Locker only defined for nt and posix platforms")
21 Lock first 10 bytes of a file.
30 msvcrt.locking(file.fileno(),msvcrt.LK_LOCK,10)
39 Unlock first 10 bytes of a file.
43 msvcrt.locking(file.fileno(),msvcrt.LK_UNLCK,10)
46 elif os.name ==
'posix':
50 return "%s.%s.%d" % ( fileName, socket.gethostname(), os.getpid() )
52 return "%s.lock" % fileName
56 return os.stat(lockFileName).st_nlink
58 if e.errno != errno.ENOENT:
64 try: readFileName = fp.read()
67 except EnvironmentError, e:
68 if e.errno != errno.ENOENT:
77 fp = open( tmpFileName,
"w" )
78 fp.write( tmpFileName )
85 os.link( tmpFileName, lockFileName )
89 if e.errno == errno.ENOENT:
91 elif e.errno != errno.EEXIST:
92 os.unlink(tmpFileName)
96 elif _read(lockFileName) == tmpFileName:
114 os.unlink( lockFileName )
116 if e.errno != errno.ENOENT:
120 os.unlink( tmpFileName )
122 if e.errno != errno.ENOENT:
136 self.
log = logging.getLogger(
"LockFile")
137 self.log.info(
"%s - Locking on %s", time.strftime(
"%Y-%m-%d_%H:%M:%S"), self.
name)
138 if not os.path.exists(name):
147 self.log.warning(
"Cannot acquire lock on %s", self.
name)
157 self.log.info(
"%s - Lock on %s released", time.strftime(
"%Y-%m-%d_%H:%M:%S"), self.
name)