def acquire_lock_or_exit(self, wait_for_seconds=10):
lock_file = self.STATE_DIR + '/.iptables.lock'
i = 0
f = open(lock_file, 'w+')
while i < wait_for_seconds:
try:
fcntl.flock(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
return
except IOError:
i += 1
time.sleep(1)
Iptables.module.fail_json(msg="Could not acquire lock to continue execution! "
"Probably another instance of this module is running.")
# Check if a table has anything to flush (to check all tables pass table='*').
iptables_raw.py 文件源码
python
阅读 19
收藏 0
点赞 0
评论 0
评论列表
文章目录