当前位置: 首页>>代码示例>>Python>>正文


Python lockfile.FileLock方法代码示例

本文整理汇总了Python中lockfile.FileLock方法的典型用法代码示例。如果您正苦于以下问题:Python lockfile.FileLock方法的具体用法?Python lockfile.FileLock怎么用?Python lockfile.FileLock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lockfile的用法示例。


在下文中一共展示了lockfile.FileLock方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __enter__

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def __enter__(self):
        if self.options.splay > 0:
            splay = randint(0, self.options.splay)
            self.logger.debug('Sleeping for %d seconds (splay=%d)' %
                              (splay, self.options.splay))
            time.sleep(splay)
        self.start_time = DT.datetime.today()
        if not self.options.nolock:
            self.logger.debug('Attempting to acquire lock %s (timeout %s)',
                              self.options.lockfile,
                              self.options.locktimeout)
            self.lock = FileLock(self.options.lockfile)
            try:
                self.lock.acquire(timeout=self.options.locktimeout)
            except LockFailed as e:
                self.logger.error("Lock could not be acquired.")
                self.logger.error(str(e))
                sys.exit(1)
            except LockTimeout as e:
                msg = "Lock could not be acquired. Timeout exceeded."
                self.logger.error(msg)
                sys.exit(1) 
开发者ID:jjneely,项目名称:whisper-backup,代码行数:24,代码来源:pycronscript.py

示例2: test_other_process_locks

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def test_other_process_locks(self):
        """Test locking the state in another process locks
        """
        with tempfile.NamedTemporaryFile() as temp:
            def other_op(queue):
                """Lock the lockfile, then wait for poison pill
                """
                lockfile.FileLock(temp.name).acquire()
                while queue.empty():
                    sleep(0.01)
                lockfile.FileLock(temp.name).release()

            queue = multiprocessing.Queue()
            process = multiprocessing.Process(target=other_op,
                                              args=(queue,))
            process.start()

            while not lockfile.FileLock(temp.name).is_locked():
                sleep(0.01)
            StateHandler.STATE_LOCK_TIMEOUT = 0.001
            handler = StateHandler(temp.name, load=False)
            self.assertRaises(RuntimeError, handler.lock)
            queue.put(None)
            process.join() 
开发者ID:duerrp,项目名称:pyexperiment,代码行数:26,代码来源:test_state.py

示例3: generate_or_read_from_file

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def generate_or_read_from_file(key_file='.secret_key', key_length=64):
    """Multiprocess-safe secret key file generator.

    Useful to replace the default (and thus unsafe) SECRET_KEY in settings.py
    upon first start. Save to use, i.e. when multiple Python interpreters
    serve the dashboard Django application (e.g. in a mod_wsgi + daemonized
    environment).  Also checks if file permissions are set correctly and
    throws an exception if not.
    """
    lock = lockfile.FileLock(key_file)
    with lock:
        if not os.path.exists(key_file):
            key = generate_key(key_length)
            old_umask = os.umask(0o177)  # Use '0600' file permissions
            with open(key_file, 'w') as f:
                f.write(key)
            os.umask(old_umask)
        else:
            if (os.stat(key_file).st_mode & 0o777) != 0o600:
                raise FilePermissionError("Insecure key file permissions!")
            with open(key_file, 'r') as f:
                key = f.readline()
        return key 
开发者ID:CiscoSystems,项目名称:avos,代码行数:25,代码来源:secret_key.py

示例4: _lock_state_file

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def _lock_state_file(self):
        if not self.lock:
            return
        self._lockfile = LockFile(self.path)

        if (self._lockfile.is_locked() and
                (time() - getmtime(self._lockfile.lock_file)) > 10):
            self._lockfile.break_lock()

        self._lockfile.acquire() 
开发者ID:bq,项目名称:web2board,代码行数:12,代码来源:app.py

示例5: __init__

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def __init__(self, timeout=2):
        """Create the lock file and lock file object and obtains a lock."""
        # Create lock file, if it does not exist
        if not os.path.isfile(DirectoryLocation.LOCK_FILE):
            if not os.path.isdir(DirectoryLocation.LOCK_FILE_DIR):
                os.mkdir(DirectoryLocation.LOCK_FILE_DIR)
            open(DirectoryLocation.LOCK_FILE, 'a').close()

        # Attempt to lock lockfile
        DaemonLock.LOCK = FileLock(DirectoryLocation.LOCK_FILE)

        # Check if lockfile object is already locked
        if DaemonLock.LOCK.is_locked():
            raise MCVirtLockException('An instance of MCVirt is already running') 
开发者ID:ITDevLtd,项目名称:MCVirt,代码行数:16,代码来源:daemon_lock.py

示例6: __init__

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def __init__(self, name, maxattempts, filename, logger):
        self.name = name
        self.filename = filename
        self.maxattempts = maxattempts
        self.filelock = lockfile.FileLock(self.filename)
        self.counter = 0
        self.logger = logger 
开发者ID:openweave,项目名称:happy,代码行数:9,代码来源:Driver.py

示例7: write_tuning_result

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def write_tuning_result(params: dict, result: dict, df_path: str):
    row = pd.DataFrame()
    for key in params['tuning_params']:
        row[key] = [params[key]]

    for key, val in result.items():
        row[key] = val

    with lockfile.FileLock(df_path):
        df_results = pd.read_csv(df_path)
        df_results = pd.concat([df_results, row], sort=False).reset_index(drop=True)
        df_results.to_csv(df_path, index=None) 
开发者ID:lyakaap,项目名称:Landmark2019-1st-and-3rd-Place-Solution,代码行数:14,代码来源:utils.py

示例8: download

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def download(self):
        self._mkdir_p(self.local_directory)
        with FileLock(self.lock_location):
            if not self._check_binary_present():
                self._download_binary() 
开发者ID:botify-labs,项目名称:simpleflow,代码行数:7,代码来源:download.py

示例9: _download_binary

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def _download_binary(self):
        logger.info("Downloading binary: {} -> {}".format(self.remote_location, self.local_location))
        bucket, path = self.remote_location.replace("s3://", "", 1).split("/", 1)
        # with FileLock(dest):
        pull(bucket, path, self.local_location)
        os.chmod(self.local_location, 0o755)


# convenience helpers 
开发者ID:botify-labs,项目名称:simpleflow,代码行数:11,代码来源:download.py

示例10: IncRunID

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def IncRunID(project_name, db_dir):
    """Increment the RunID and append new value with project name to the file"""
    database_file = db_dir + '/runID_database.txt'

    # lock the file
    lock = lf.FileLock(database_file)
    while not lock.i_am_locking():
        try:
            # wait up to 10 seconds
            lock.acquire(timeout=5)
        except lf.LockTimeout:
            raise Exception(
                'ERROR: Timed out waiting for file lock at ' + lock.path)

    # get the last run_id from the db file
    rundb = open(database_file, 'r')
    for line in rundb:
        (old_id, old_project) = line.split()

    rundb.close()
    global run_id
    run_id = int(old_id) + 1

    # write the incremented run_id with project name to the db file
    with open(database_file, 'a') as rundb:
        rundb.write(str(run_id) + '\t' + project_name + '\n')

    rundb.close()
    lock.release()

    return 
开发者ID:pughlab,项目名称:bamgineer,代码行数:33,代码来源:runIDHelpers.py

示例11: lock

# 需要导入模块: import lockfile [as 别名]
# 或者: from lockfile import FileLock [as 别名]
def lock(self):
        """Lock the state file
        """
        self.state_lock = lockfile.FileLock(self.filename)
        try:
            self.state_lock.acquire(timeout=self.STATE_LOCK_TIMEOUT)
        except lockfile.LockTimeout:
            raise RuntimeError("Cannot acquire lock on state file ('%s'), "
                               "check if another process is using it"
                               % self.filename) 
开发者ID:duerrp,项目名称:pyexperiment,代码行数:12,代码来源:State.py


注:本文中的lockfile.FileLock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。