Files
clang-p2996/lldb/test/lock.py
Vince Harron 05df698d2b Darwin - fix intermitent crashes in import crashinfo
Summary:
"import crashinfo" was probably failing because multiple dotest invocations
are all trying to compile crashinfo.so at the same time.
    
I've put a mutex around the compile step to prevent this.
   
Reviewers: clayborg, chying
    
Subscribers: lldb-commits
    
Differential Revision: http://reviews.llvm.org/D9732

llvm-svn: 237230
2015-05-13 05:00:23 +00:00

24 lines
512 B
Python

"""
Interprocess mutex based on file locks
"""
import fcntl
import os
class Lock:
def __init__(self, filename):
self.filename = filename
# This will create it if it does not exist already
self.handle = open(filename, 'w')
# Bitwise OR fcntl.LOCK_NB if you need a non-blocking lock
def acquire(self):
fcntl.flock(self.handle, fcntl.LOCK_EX)
def release(self):
fcntl.flock(self.handle, fcntl.LOCK_UN)
def __del__(self):
self.handle.close()