autotest: use a lock file

this ensures we don't run two copies of the tests at once
This commit is contained in:
Andrew Tridgell 2011-11-09 23:53:09 +11:00
parent c2fd7144e2
commit d98f3ebd0c
2 changed files with 16 additions and 0 deletions

View File

@ -243,6 +243,12 @@ def run_tests(steps):
return passed
lck = util.lock_file(util.reltopdir('../buildlogs/autotest.lck'))
if lck is None:
print("autotest is locked - exiting")
sys.exit(0)
try:
if not run_tests(steps):
sys.exit(1)

View File

@ -160,3 +160,13 @@ def loadfile(fname):
r = f.read()
f.close()
return r
def lock_file(fname):
'''lock a file'''
import fcntl
f = open(fname, mode='w')
try:
fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
except Exception:
return None
return f