Section critique non bloquante

darcs-hash:20041205133447-d1718-952ffc9db50a4b41190f9be0565e416d99cbaf4a.gz
This commit is contained in:
bernat 2004-12-05 14:34:47 +01:00
parent bd4e952af8
commit d81797c847

View file

@ -32,9 +32,17 @@ def make_lock(lock_name, lock_comment='',nowait=1, quiet=False) :
except IOError, e:
if e.errno not in [errno.EACCESS, errno.EAGAIN]:
raise
# La procédure de lock est deja en cours d'execution, on essaie un peu plus tard
time.sleep(0.5)
return make_lock(lock_name, lock_comment)
if nowait:
if quiet:
# On va plutot lever une exception
raise AssertionError('In critical section')
else:
sys.stderr.write('\tpropriétaire : inconnu\n\tpid : inconnu\n\tdémarré depuis inconnu\n')
sys.exit(254)
else:
# La procédure de lock est deja en cours d'execution, on essaie un peu plus tard
time.sleep(0.5)
return make_lock(lock_name, lock_comment)
if os.path.isfile(lock_file) :
### Lock existant