2 Interprocess mutex based on file locks
10 def __init__(self
, filename
):
11 self
.filename
= filename
12 # This will create it if it does not exist already
14 self
.handle
= open(filename
, 'a+', unbuffered
)
17 fcntl
.flock(self
.handle
, fcntl
.LOCK_EX
)
19 # will throw IOError if unavailable
20 def try_acquire(self
):
21 fcntl
.flock(self
.handle
, fcntl
.LOCK_NB | fcntl
.LOCK_EX
)
24 fcntl
.flock(self
.handle
, fcntl
.LOCK_UN
)