util.py 文件源码

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

项目:TCP-IP 作者: JackZ0 项目源码 文件源码
def lock_and_call(func, lock_path):
    """Grab a lock for lock_path and call func.

    :param callable func: object to call after acquiring the lock
    :param str lock_path: path to file or directory to lock

    """
    # Reload module to reset internal _LOCKS dictionary
    reload_module(util)

    # start child and wait for it to grab the lock
    cv = multiprocessing.Condition()
    cv.acquire()
    child_args = (cv, lock_path,)
    child = multiprocessing.Process(target=hold_lock, args=child_args)
    child.start()
    cv.wait()

    # call func and terminate the child
    func()
    cv.notify()
    cv.release()
    child.join()
    assert child.exitcode == 0
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号