config.py 文件源码

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

项目:webmon 作者: KarolBedkowski 项目源码 文件源码
def _try_lock():
    """Check and create lock file - prevent running application twice.

    Return lock file handler.
    """
    lock_file_path = _find_config_file("app.lock", False)
    _check_dir_for_file(lock_file_path)
    try:
        if fcntl is not None:
            lock_file = open(lock_file_path, "w")
            fcntl.lockf(lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
        else:
            if os.path.isfile(lock_file_path):
                _LOG.error("another instance detected (lock file exists) "
                           "- exiting")
                return None
            lock_file = open(lock_file_path, "w")
        return lock_file
    except IOError as err:
        import errno
        if err.errno == errno.EAGAIN:
            _LOG.error("another instance detected - exiting")
        else:
            _LOG.exception("locking failed: %s", err)
    return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号