修改枷锁方式
This commit is contained in:
parent
8693fa8699
commit
25fa1598de
|
@ -620,26 +620,30 @@ def get_package_label(pkg):
|
|||
name = getattr(pkg.candidate, "summary", "")
|
||||
return capitalize_first_word(name)
|
||||
|
||||
#安装时禁止关机 进行加锁
|
||||
def LockedPreventShutdown():
|
||||
global locked
|
||||
|
||||
#加锁后直接返回
|
||||
if locked:
|
||||
return
|
||||
|
||||
#锁目录是否存在 不存在时 创建
|
||||
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:
|
||||
locked = True
|
||||
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
|
||||
|
||||
#解锁禁止关机
|
||||
def unLockedEnableShutdown():
|
||||
global locked
|
||||
|
||||
|
|
Loading…
Reference in New Issue