diff --git a/gestion/lock.py b/gestion/lock.py index efbac31b..e81251c3 100755 --- a/gestion/lock.py +++ b/gestion/lock.py @@ -13,7 +13,7 @@ from user_tests import getuser from fcntl import lockf, LOCK_EX, LOCK_NB, LOCK_UN import errno -def make_lock(lock_name, lock_comment='',nowait=1) : +def make_lock(lock_name, lock_comment='',nowait=1, quiet=False) : """ Création d'un lock si nowait=1 fait un sys.exit(254) quand un ancien lock actif est rencontré """ @@ -45,7 +45,8 @@ def make_lock(lock_name, lock_comment='',nowait=1) : # Le script lockant ne tourne plus os.remove(lock_file) elif nowait : - sys.stderr.write('Lock : %s\n' % lock_file) + if not quiet: + sys.stderr.write('Lock : %s\n' % lock_file) l=getoutput('ps -o etime --no-headers %s' % pid) data = [ user , pid , l.strip() ] @@ -67,9 +68,13 @@ def make_lock(lock_name, lock_comment='',nowait=1) : txt = '???' data[-1]=txt - - sys.stderr.write('\tpropriétaire : %s\n\tpid : %s\n\tdémarré depuis %s\n' % tuple(data) ) - sys.exit(254) + + if not quiet: + sys.stderr.write('\tpropriétaire : %s\n\tpid : %s\n\tdémarré depuis %s\n' % tuple(data) ) + sys.exit(254) + else: + # On va plutot lever une exception + raise AssertionError(tuple(data)) else : # Il faut attendre a = affich_tools.anim('\tattente du lock')