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 bc08189613
commit 4ed5eb477a
2 changed files with 16 additions and 0 deletions

View File

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

View File

@ -160,3 +160,13 @@ def loadfile(fname):
r = f.read() r = f.read()
f.close() f.close()
return r 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