Verrou exclusif pour retirer le lock aussi (et bloquant, mais bon)
darcs-hash:20050317083907-d1718-e7b5e1d000a89cc53efad2aabcc0a0041093d707.gz
This commit is contained in:
parent
09111d4ddb
commit
906418cf57
1 changed files with 16 additions and 0 deletions
|
@ -144,8 +144,20 @@ def make_lock(lock_name, lock_comment='',nowait=0, quiet=False) :
|
||||||
|
|
||||||
def remove_lock( lock_name ) :
|
def remove_lock( lock_name ) :
|
||||||
""" Destruction du lock """
|
""" Destruction du lock """
|
||||||
|
# On créé une zone d'exclusion
|
||||||
lock_dir = '/var/lock/gestion'
|
lock_dir = '/var/lock/gestion'
|
||||||
lock_file = "%s/%s" % (lock_dir, lock_name)
|
lock_file = "%s/%s" % (lock_dir, lock_name)
|
||||||
|
|
||||||
|
lock_fd_dl=open("%s-dotlock" % lock_file, "w")
|
||||||
|
# On demande un verrou exclusif
|
||||||
|
try:
|
||||||
|
lockf(lock_fd_dl, LOCK_EX | LOCK_NB)
|
||||||
|
except IOError, e:
|
||||||
|
if e.errno not in [errno.EACCES, errno.EAGAIN]:
|
||||||
|
raise
|
||||||
|
# Déjà locké
|
||||||
|
time.sleep(0.5)
|
||||||
|
return remove_lock(lock_name)
|
||||||
try :
|
try :
|
||||||
fd = open(lock_file, "r")
|
fd = open(lock_file, "r")
|
||||||
if fd.readline().strip()=="%s" % os.getpid():
|
if fd.readline().strip()=="%s" % os.getpid():
|
||||||
|
@ -153,3 +165,7 @@ def remove_lock( lock_name ) :
|
||||||
fd.close()
|
fd.close()
|
||||||
except :
|
except :
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# On enleve le verrou système
|
||||||
|
lockf(lock_fd_dl, LOCK_UN)
|
||||||
|
lock_fd_dl.close()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue