修改枷锁方式

This commit is contained in:
wangsong 2021-11-03 10:55:04 +08:00
parent 8693fa8699
commit 25fa1598de
1 changed files with 20 additions and 16 deletions

View File

@ -620,26 +620,30 @@ def get_package_label(pkg):
name = getattr(pkg.candidate, "summary", "")
return capitalize_first_word(name)
#安装时禁止关机 进行加锁
def LockedPreventShutdown():
global locked
global locked
if locked:
return
#加锁后直接返回
if locked:
return
#锁目录是否存在 不存在时 创建
if not os.path.exists(FILELOCK_PATH):
os.makedirs(FILELOCK_PATH)
if not os.path.exists(FILELOCK_PATH):
os.makedirs(FILELOCK_PATH)
with open(os.path.join(FILELOCK_PATH, SHUTDOWN_BLOCK_FILELOCK), "w+") as pidfile:
try:
fcntl.flock(pidfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
locked = True
logging.info("Has been locked.")
#多次加锁就会出现异常
except Exception as e:
logging.error(e)
locked = False
logging.error("file cannot be locked.")
return False
with open(os.path.join(FILELOCK_PATH, SHUTDOWN_BLOCK_FILELOCK), "w+") as pidfile:
try:
locked = True
fcntl.flock(pidfile, fcntl.LOCK_EX | fcntl.LOCK_NB)
logging.info("Has been locked.")
except Exception as e:
logging.error(e)
locked = False
logging.error("file cannot be locked.")
return False
#解锁禁止关机
def unLockedEnableShutdown():
global locked