lockfile.py 文件源码

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

项目:nrp 作者: django-rea 项目源码 文件源码
def __init__(self, path, threaded=True):
        """
        >>> lock = LockBase("somefile")
        >>> lock = LockBase("somefile", threaded=False)
        """
        self.path = path
        self.lock_file = os.path.abspath(path) + ".lock"
        self.hostname = socket.gethostname()
        self.pid = os.getpid()
        app_name = "-test"
        if threaded:
            name = threading.current_thread().get_name()
            tname = "%s-" % quote(name, safe="")
        else:
            tname = ""
        dirname = os.path.dirname(self.lock_file)
        self.unique_name = os.path.join(dirname,
                                        "%s%s.%s%s" % (self.hostname,
                                                     app_name,
                                                     tname,
                                                     self.pid))
        msg = " ".join(["lock_file:", self.lock_file])
        logger.debug(msg)
        msg = " ".join(["unique_name:", self.unique_name])
        logger.debug(msg)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号