filelock.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:ZeroExploit 作者: 5alt 项目源码 文件源码
def acquire(self):
        """ Acquire the lock, if possible. If the lock is in use, it check again
            every `wait` seconds. It does this until it either gets the lock or
            exceeds `timeout` number of seconds, in which case it throws
            an exception.
        """
        start_time = time.time()
        while True:
            try:
                self.fd = os.open(self.lockfile, os.O_CREAT|os.O_EXCL|os.O_RDWR)
                break
            except OSError as e:
                if e.errno != errno.EEXIST:
                    raise
                if (time.time() - start_time) >= self.timeout:
                    raise FileLockTimeoutException("%d seconds passed." % self.timeout)
                time.sleep(self.delay)
        self.is_locked = True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号