util.py 文件源码

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

项目:Taigabot 作者: FrozenPigs 项目源码 文件源码
def _obtain_lock_or_raise(self):
        """Create a lock file as flag for other instances, mark our instance as lock-holder

        :raise IOError: if a lock was already present or a lock file could not be written"""
        if self._has_lock():
            return
        lock_file = self._lock_file_path()
        if osp.isfile(lock_file):
            raise IOError("Lock for file %r did already exist, delete %r in case the lock is illegal" %
                          (self._file_path, lock_file))

        try:
            flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL
            if is_win:
                flags |= os.O_SHORT_LIVED
            fd = os.open(lock_file, flags, 0)
            os.close(fd)
        except OSError as e:
            raise IOError(str(e))

        self._owns_lock = True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号