bitbake utils.py: Fix ocassional locking glitch with a better retrying mechanism
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@5415 311d38ba-8fff-0310-9ca6-ca027cbcb966
This commit is contained in:
parent
527b3372cd
commit
f4337b9803
|
@ -246,15 +246,18 @@ def lockfile(name):
|
||||||
# This implementation is unfair since the last person to request the
|
# This implementation is unfair since the last person to request the
|
||||||
# lock is the most likely to win it.
|
# lock is the most likely to win it.
|
||||||
|
|
||||||
lf = open(name, "a+")
|
try:
|
||||||
fcntl.flock(lf.fileno(), fcntl.LOCK_EX)
|
lf = open(name, "a+")
|
||||||
statinfo = os.fstat(lf.fileno())
|
fcntl.flock(lf.fileno(), fcntl.LOCK_EX)
|
||||||
if os.path.exists(lf.name):
|
statinfo = os.fstat(lf.fileno())
|
||||||
statinfo2 = os.stat(lf.name)
|
if os.path.exists(lf.name):
|
||||||
if statinfo.st_ino == statinfo2.st_ino:
|
statinfo2 = os.stat(lf.name)
|
||||||
return lf
|
if statinfo.st_ino == statinfo2.st_ino:
|
||||||
# File no longer exists or changed, retry
|
return lf
|
||||||
lf.close
|
# File no longer exists or changed, retry
|
||||||
|
lf.close
|
||||||
|
except Exception, e:
|
||||||
|
continue
|
||||||
|
|
||||||
def unlockfile(lf):
|
def unlockfile(lf):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -246,15 +246,18 @@ def lockfile(name):
|
||||||
# This implementation is unfair since the last person to request the
|
# This implementation is unfair since the last person to request the
|
||||||
# lock is the most likely to win it.
|
# lock is the most likely to win it.
|
||||||
|
|
||||||
lf = open(name, "a+")
|
try:
|
||||||
fcntl.flock(lf.fileno(), fcntl.LOCK_EX)
|
lf = open(name, "a+")
|
||||||
statinfo = os.fstat(lf.fileno())
|
fcntl.flock(lf.fileno(), fcntl.LOCK_EX)
|
||||||
if os.path.exists(lf.name):
|
statinfo = os.fstat(lf.fileno())
|
||||||
statinfo2 = os.stat(lf.name)
|
if os.path.exists(lf.name):
|
||||||
if statinfo.st_ino == statinfo2.st_ino:
|
statinfo2 = os.stat(lf.name)
|
||||||
return lf
|
if statinfo.st_ino == statinfo2.st_ino:
|
||||||
# File no longer exists or changed, retry
|
return lf
|
||||||
lf.close
|
# File no longer exists or changed, retry
|
||||||
|
lf.close
|
||||||
|
except Exception, e:
|
||||||
|
continue
|
||||||
|
|
||||||
def unlockfile(lf):
|
def unlockfile(lf):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue