filelock.py 文件源码

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

项目:PY-Snip 作者: MrKiven 项目源码 文件源码
def with_multi_lock(tag, n, unlock_after_with=True):

    get_lock_file_path = lambda i: os.path.join(
        '/tmp/', tag + '.lock' + (str(i) if i else ''))

    for i in range(n):
        lock_file_path = get_lock_file_path(i)
        fd = os.open(lock_file_path, os.O_CREAT | os.O_RDWR, 0660)
        try:
            if trylock(fd):
                yield True
                break
        finally:
            if unlock_after_with:
                os.close(fd)
    else:
        yield False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号