def lock(lockfile):
def decorator(clbl):
def wrapper(*args, **kwargs):
try:
# Create or fail
os.open(lockfile, os.O_CREAT | os.O_EXCL)
except OSError:
raise BackupError("Another backup process already running."
" If it is not, try to remove `{0}` and "
"try again.".format(lockfile))
try:
result = clbl(*args, **kwargs)
finally:
os.unlink(lockfile)
return result
return wrapper
return decorator
评论列表
文章目录