locks.py 文件源码

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

项目:micromasters 作者: mitodl 项目源码 文件源码
def _get_lock(lock_name, expiration):
    """
    Creates a new redis LuaLock

    Args:
        lock_name (str): The name of the lock
        expiration (datetime.datetime): The expiration datetime

    Returns:
        redis.lock.LuaLock: a redis lua-based lock
    """
    timeout = int((expiration - now_in_utc()).total_seconds())

    # this is a StrictRedis instance, we need this for the script installation that LuaLock uses
    redis = caches['redis'].client.get_client()
    # don't block acquiring the lock, the task will need to try again later
    return LuaLock(redis, lock_name, timeout=timeout, blocking=False, thread_local=False)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号